in reply to Re: Re: Associative Array Trouble
in thread Associative Array Trouble

Your second take is much better, much more indented, but try and keep things neat. Your closing brace in your foreach, for example, is strangely at the end of a line which is also sans-semicolon.

Anyway, to "derefence" something is to take a reference and use it to obtain a value. References are what make people exposed to C for the first time look all green and dizzy, but they're really not that bad, especially in Perl.

Here's a really, really brief introduction to references:
my @array = qw[ 1 2 3 ]; my $array_ref = \@array; # Backslash makes a reference my @array_copy = @$array_ref; # @ de-references array reference $array[2] = 4; # Modifies @array directly print $array_ref->[2]; # Should be '4' now $array_ref->[1] = 5; # Modifies @array by reference print $array[1]; # Should be '5' $array_copy[1] = 6; # Modifies @array_copy, not @array print $array[1]; # Still '5'
For a much more detailed document, check out perlref.

Fortunately, or unfortunately depending on your opinion, Perl will automagically dereference for you in certain circumstances. Where $foo->{bar} is actually an "ARRAY" reference, you should really sub-address that as $foo->{bar}->[1] and not $foo->{bar}[1], but either should work.