in reply to dereferencing hash within a hash within an array

Update:Ignore this! Its a complete red-herring bought about by brain-fade.

if ($data[$x]->{'anaglyph'} eq "Yes"){ $data[$x]->{'anaglyph'}="checked"; }

To clarify: If the array element $data[$x] contains a valid reference to a hash, then you need dereference that using -> to indicate that this is the case.


Examine what is said, not who speaks.

The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.

Replies are listed 'Best First'.
Re: Re: dereferencing hash within a hash within an array
by sauoq (Abbot) on Jan 10, 2003 at 23:20 UTC
    To clarify: If the array element $data[$x] contains a valid reference to a hash, then you need dereference that using -> to indicate that this is the case.

    No, you don't need to do so.

    my %h = ( foo => 'bar' ); my @a = ( \%h ); print "worked fine\n" if $a[0]{foo} eq 'bar';

    You need to use the arrow when you are dealing directly with a scalar containing a reference rather than a nested one.

    my %h = ( foo => 'bar' ); my @a = ( \%h ); my $r = \@a; print $r->[0]{foo}, "\n"; # $r[0] won't work since @r doesn't exist.
    -sauoq
    "My two cents aren't worth a dime.";