I've been trying to setup a a script that needs to print a hash of
arrays. The catch: The arrays are meant to be blocks of text.
Here is the code:
QUOTE |
#!/usr/bin/perl use warnings; use strict; open FILE, ">subroutines" or die "Cannot create output file"; my $name; my %subroutines; my $subroutines; my @sub_code; my $line; my $flag = 0; while(defined($line = <>)) { if ($line =~ /^s+bSUBROUTINEbs+(w+)s*(/i) { $flag = 1; $name = $1; #print "$name n"; } elsif ($line =~/^s+ENDs*/i) { $flag = 0; } if ($flag) { #print $_; push(@sub_code, "$line"); #print @sub_code; } else { $subroutines{$name} = [ @sub_code ]; @sub_code = [""]; } } foreach $name ( keys %subroutines ) { print "$name: n"; # my $i=0; # while (defined($subroutines->{$name}[$i])) { print "t@{ $subroutines{$name} }n"; # $i++; # } } close FILE; |
QUOTE |
: ARRAY(0x8158788) READOPAC: ARRAY(0x814a464) CO: ARRAY(0x816c5e8) OPASURFB: ARRAY(0x81546fc) engen: ARRAY(0x814c650) OPALA: ARRAY(0x814c5e4) opacty: ARRAY(0x816dbc4) SPLINT: ARRAY(0x816c528) OPASURFA: ARRAY(0x814c578) SPLINE: ARRAY(0x816c540) OPACITY: ARRAY(0x814c314) POLINT: ARRAY(0x816c4ec) vtrue: ARRAY(0x816c480) OPALB: ARRAY(0x814c3bc) SPLIN2: ARRAY(0x816c5ac) SPLIE2: ARRAY(0x816c558) |