in reply to dynamic 2d array

You never actually stated what the problem is or what the error you are getting is, but if it is what I think (without running the code() is is, try adding:
$d_array[$line_number]=[];
right after the $line_number++ line. That will properly initialize the inner array.
you will still have a problem though, you need to either initialize $line_number to -1 before the loop, or move the $line_number++ to the end to avoid having your loop start at 1;


-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

Replies are listed 'Best First'.
Re^2: dynamic 2d array
by Anonymous Monk on Aug 14, 2008 at 00:08 UTC
    Sorry, my bad. Been up all night trying to fix this thing and getting a little groggy. The error is this:

    Global symbol "@d_array" requires explicit package name at ./subtest.p +l line 10. Execution of ./subtest.pl aborted due to compilation errors.
      As you have it, the scope of the my @d_array does not include your sub printRow. Move the sub declaration to the end, or move the my declaration to the top.

      Also, you probably want to be passing array refereces to Dumper (or at least be aware of the different output in the two cases):

      use strict; use warnings; use Data::Dumper; my @ar = qw( a b c ); print Dumper(\@ar); print Dumper(@ar); __END__ $VAR1 = [ 'a', 'b', 'c' ]; $VAR1 = 'a'; $VAR2 = 'b'; $VAR3 = 'c';