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

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -