----- Original Message ----- 
From: "John W. Krahn" <[EMAIL PROTECTED]>
To: "Wiggins d Anconia" <[EMAIL PROTECTED]>; "Perl Beginners"
<[EMAIL PROTECTED]>
Sent: Friday, October 15, 2004 11:30 PM
Subject: Re: Reference syntax...


> 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.

and just above it there is an interesting example...

        for $i (1..10) {
            @array = somefunc($i);
            $AoA[$i] = [ @array ];
        }

    The square brackets make a reference to a new array with a *copy* of
    what's in @array at the time of the assignment. This is what you want.

if one has a ref to HoH how would he make a copy of it using simular syntax
?? I know it can be done like this

use Storable qw(dclone);
my $HOH_REF_COPY  =  dclone($HOH_REF)

>
>
>
> 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>
>
>
>



-- 
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