NodeReaper has asked for the wisdom of the Perl Monks concerning the following question:

This node was taken out by the NodeReaper on Wed Jul 28 10:53:47 2004 (EST)

Replies are listed 'Best First'.
Re: multi dimension array
by graff (Chancellor) on Jul 28, 2004 at 12:54 UTC
    I didn't see anything wrong with the answers you got the fist time you posted this question.

    Was the repeated post a mistake, or were you having trouble finding your earlier post?

    (update: fixed link)

Re: multi dimension array
by davorg (Chancellor) on Jul 28, 2004 at 12:35 UTC

    The indexes for arrays can only be integers, not strings as you have there. You need hashes not arrays.

    See "perldoc perldsc" for mre details and many examples.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re: multi dimension array
by borisz (Canon) on Jul 28, 2004 at 12:40 UTC
    I whould use a hash.
    my %h = ( fruits => { p => [ 'peach' ], g => [ 'grapes' ], }, birds => { p => [ 'parrot' ], c => [ 'crow' ], } );
    Get all fruits with p
    @all_p_fruits = @{$h{fruits}->{p}};
    to add a fruit use
    push @{$h{fruits}->{p}}, 'peach_yellow';
    Boris
Re: multi dimension array
by ChuckularOne (Prior) on Jul 28, 2004 at 12:40 UTC
    use Data::Dumper; $a = "fruits"; $b = "birds"; $c = "p"; $d = "g"; $e = "c"; $array1{$a}{$c}= [ "peach" ]; $array1{$a}{$d}= [ "grapes" ]; $array1{$b}{$c}= [ "parrot" ]; $array1{$b}{$e}= [ "crow" ]; print Dumper %array1;
    This is the way to do it as a hash. I doubt this is helpful though.


    Update: Added missing square brackets. (I guess I should have tested it.)
    Better yet use borisz's example below.