Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: 2 dimensional array question

by Roger (Parson)
on Sep 05, 2005 at 14:13 UTC ( #489230=note: print w/replies, xml ) Need Help??

in reply to 2 dimensional array question

Note that your assignment is using array slices @arr[0] and @arr[1]. Although it works, you should use $arr[0] and $arr[1] instead because they are not the same thing.

You could use the following method to initialize the 2-d array (use qw // and no commas, I hate to type commas :-)
@arr = ( [ qw/ 1 2 3 / ], [ qw/ 4 5 6 / ] );

Note that [ ... ] builds a reference to an array, it has 0 dimension. While ( ... ) builds an array, which has 1 dimension. When you assign an array to a zero dimension element @arr[0] or $arr[0], it only picks the first element from your array.

And also you could use Data::Dumper to inspect your array afterwards.
use Data::Dumper; @arr = ( [ qw/ 1 2 3 / ], [ qw/ 4 5 6 / ] ); print Dumper(\@arr); # and in your case @arr[0] = qw/ 1 2 3 /; @arr[1] = qw/ 4 5 6 /; print Dumper(\@arr);

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://489230]
LanX oh my god it's full of hacks!!! ...
[holli]: what? the pm code you swindled your way into?
[LanX]: no already the pm code I'm allowed to see ... http://www. 1203338;style=css
[LanX]: understanding this code is like relearning space invaders and donkey Kong at the same time

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2017-11-20 21:32 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (294 votes). Check out past polls.