How can I create a variable array name in Perl? -
array @p multiline array, e.g. $p[1] second line.
this code explain want:
$size=@p; # line number of array @p for($i=0; $i<$size; $i++) { @p{$i}= split(/ +/,$p[$i]); }
i want result should this:
@p0 = $p[0] first line of array @p goes array @p0; @p1 = $p[1] second line of array @p goes array @p1; ... ...
and on.
but above code not work, how can it?
it bad idea dynamically generate variable names.
i suggest best solution here convert each line in @p
array array of fields.
lets suppose have better name @p
, @lines
. can write
my @lines = map [ split ], <$fh>;
to read in lines file handle $fh
, split them on whitespace. first field of first line $lines[0][0]
. third field of first line $lines[0][2]
etc.
Comments
Post a Comment