Bryan,
There are other instances than the example below but this one tripped me
recently.
my %exhash = ( one => 1,
two => 2,
thr => 3 );
my $href = \%exhash;
my @exary = qw ( zero one two thr four);
print $$href{$exary[$$href{two}]}, "\n";
# $$href{two} is 2
# used as a subscript for the array is two
# used as a hash key yields 2 - no big deal
# but
%exhash = ( one => 1,
two => \@exary,
thr => 3 );
# now consider the below
print $ { $$href{two}}[3], "\n";
print $ $$href{two}[3], "\n"; # <------------
|
the final print statement yields: |
Not a SCALAR reference at ./list_h.pl line 18.-
This is a contrived example but recently I was 'gaming' and using hash refs
whose target hashes
had array references in some of the values, and it had me stumped until I
remembered braces can be used to
disambiguate references.
print $href->{two}->[3];
Is another way to do the same job.
Clear as mud?
"Bryan R Harris" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> Quick question:
>
> When exactly are {} braces required? I notice when following references,
> $ { $var } and $$var both work identically. Do you ever actually need
> them?
>
> - B
>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]