Wiggins d Anconia wrote:

Usually when you need this is when you have multiple depths of references and the syntax becomes ambiguous to the interpreter. Something like,

@{$hashref->{$scalar}}

In this case without the {} the interpreter can't tell if you mean,

Yes, the interpreter can tell because of precedence. @$hashref->{$scalar} is the same as @{$hashref}->{$scalar} which in this case will produce an error.


(@$hashref) ->{$scalar} or @ ( $hashref->{$scalar} )

The parens are NOT normal syntax, I am using them to show grouping.

perldoc perldsc [snip] CAVEAT ON PRECEDENCE Speaking of things like "@{$AoA[$i]}", the following are actually the same thing:

         $aref->[2][2]       # clear
         $$aref[2][2]        # confusing

     That's because Perl's precedence rules on its five prefix dereferencers
     (which look like someone swearing: "$ @ * % &") make them bind more
     tightly than the postfix subscripting brackets or braces!  This will no
     doubt come as a great shock to the C or C++ programmer, who is quite
     accustomed to using *a[i] to mean what's pointed to by the i'th element
     of "a".  That is, they first take the subscript, and only then deref-
     erence the thing at that subscript.  That's fine in C, but this isn't C.

     The seemingly equivalent construct in Perl, $$aref[$i] first does the
     deref of $aref, making it take $aref as a reference to an array, and then
     dereference that, and finally tell you the i'th value of the array
     pointed to by $AoA. If you wanted the C notion, you'd have to write
     "${$AoA[$i]}" to force the $AoA[$i] to get evaluated first before the
     leading "$" dereferencer.



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to