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

Hi monks, I am trying to work on a bit of code that uses multidimensional arrays to store the coordinates for an imagemap and then accesses these coords to insert the links.

However, my code doesn't work. When i try to print the value of the $coords variable, it returns an array reference, not a number - which makes me think I am accessing the values wrong.

Any advice would be lovely ;->

# @numbers contains numerical data # @links contains the name of the file where the graph is my @coords = (undef, [13,9,6], [29,9,7], [44,9,6], [59,10,6], [75,9,7] +, [91,10,5], [106,9,7], [122,9,7], [137,9,7], [152,10,6], [169,9,7], +[184,9,6]); for my $goal ( 1..12 ) { for my $well ( @numbers ) { my $img = ( $well == $goal ) ? $links[$goal-1] : "array.bmp"; my $coords = join ',', ${coords[$goal]}; # print "COORDS: @coords<P>"; print qq(<area href="http://host/cgi-bin/temp/$img" ALT="" shape="circle" coords="$coords">); } }

Replies are listed 'Best First'.
Re: accessing values from multidimensional arrays
by broquaint (Abbot) on May 30, 2003 at 09:24 UTC
Re: accessing values from multidimensional arrays
by arthas (Hermit) on May 30, 2003 at 09:35 UTC
    The arrays contained in @coords are actually array references (created using square brackets), so you should write:
    my $coords = join ',', @{$coords[$goal]};
    instead of:
    my $coords = join ',', ${coords[$goal]};
    In other words, you need to dereference your arrays.

    Michele.