in reply to Re: Hashes and Arrays
in thread Hashes and Arrays

Thanks for all your help and links. I fixed up my perl coding a bit now. However, I still have the core problem. To iterate through each row, I have to do something like this:
my $x = 0; while ($printrows[0][$x]) { print "First: $rows[0][$x]\n"; $x++; print "Second: $rows[0][$x]\n"; $x++; }
I really want to do this for each row:
my $x = 0; while ($printrows[$x][0]) { print "First: $rows[$x][0]\n"; print "Second: $rows[$x][1]\n"; }
Because, then I can reference a row directly without having to do: $x=2 X 15, $rows[0]$x to get to the 15th row.

Replies are listed 'Best First'.
Re: Re: Re: Hashes and Arrays
by sauoq (Abbot) on Jul 17, 2003 at 02:04 UTC

    You should probably forget about using a separate @printrows variable as you are initializing it to contain only one value anyway. Why not just use the original $newhash{ IP }?

    That's supposed to be an array reference anyway.

    I think I might have a handle on what you are trying to do now...

    my %newhash; push @{ $newhash{IP} }, [ 'row 0, col 0', 'row 0, col 1' ]; push @{ $newhash{IP} }, [ 'row 1, col 0', 'row 1, col 1' ]; # $newhash{ IP } contains a reference to an array with two elements. # Each element is itself a reference to an array with two elements. print $newhash{IP}->[0][0], "\n"; # row 0, col 0 print $newhash{IP}->[0][1], "\n"; # row 0, col 1 print $newhash{IP}->[1][0], "\n"; # row 1, col 0 print $newhash{IP}->[1][1], "\n"; # row 1, col 1

    -sauoq
    "My two cents aren't worth a dime.";