in reply to append array
The ouptut I get isuse Data::Dumper; my @array; # read from the file handle line by line while(<DATA>) { chomp; # split each line by ',' and save # corresponding records into the @recs array my @recs = split /\,/; # loop through the records array.. for (my $i; $i < @recs; $i++) { # and save I-th record in array # array[I]. Use @{..} to let push() know # that array[I] is also an array. push @{$array[$i]}, $recs[$i]; } } print Dumper(\@array); __DATA__ A,B,C D,B,C E,C,C
I believe this is what you were looking for?$VAR1 = [ [ 'A', 'D', 'E' ], [ 'B', 'B', 'C' ], [ 'C', 'C', 'C' ] ];
open(I,$0);<I>;$~=$/;$/='~';$_=<I>;($/)=/(.)$~/;s/[$~~]//g;/(v)/;$-=$-[0];s;\Q$/\E;$~;g;($/,$^)=/^(.)(.)/;
#% xxxxxx xx-+ xx xxx xx xx xx xx xxx xxxxx+ xx xx xxxx xxxxx ......+
#x xxxxvxxx xx xx xv xxxx x+ %+ ===== xx xx xx xx x+ =x xx xx xx xx xx ...+
#x xx xx xx xx xx xx xx xx xxx+ xxxxxx xx +x xx xx+x- xxxx xxxx ........+
#% xx xx xx xx xx xx xx x+ xx xx =+=== xx xx xxxx-xx xx =x +x xx xx xx xx ...+
#% xx xx xx -+x+ xxx+ xx xx xx xx xx x+ xx xxx+xx xx xx xxxx xx xx ....+~
for(split/$~/){s,[ $/],,g;/(.)$/;$l=$-[0];/(.)/||next;$_=chr$-+$l;$".=($1=~/$^/)?" \u$_":$_;}print$";
|
|---|