develooper Front page | perl.perl5.porters | Postings from July 2001

Re: taking a reference is an assignment?

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
July 30, 2001 01:14
Subject:
Re: taking a reference is an assignment?
Message ID:
20010730081433.656.5@bactrian.ni-s.u-net.com
Jeffrey Friedl <jfriedl@yahoo.com> writes:
>Does anyone know why the code to take a reference of a hash's key,
>
>    \$hash{KEY}
>
>results in the MOD flag on to the 'helem' at #6 below:

I assume because someone could be assigning via the refrerence:

     sub foo
     {
      my $ref = shift;
      $$ref = 'bar; 
     } 

    foo(\$hash{KEY});

In such cases one would need the slot to exist so that a reference to 
the SV * could be passed.  



>
>
>		{
>	    7       TYPE = srefgen  ===> 8
>		    FLAGS = (VOID,KIDS)
>		    {
>			TYPE = null  ===> (7)
>			  (was list)
>			FLAGS = (LIST,KIDS,REF,MOD)
>			{
>	    6               TYPE = helem  ===> 7
>			    FLAGS = (SCALAR,KIDS,REF,MOD)
>			    {
>	    4                   TYPE = rv2hv  ===> 5
>				FLAGS = (SCALAR,KIDS,REF)
>				{
>	    3                       TYPE = gv  ===> 4
>				    FLAGS = (SCALAR)
>				    GV = main::hash
>				}
>			    }
>			    {
>	    5                   TYPE = const  ===> 6
>				FLAGS = (SCALAR)
>				PRIVATE = (BARE)
>				SV = PVIV("KEY")
>			    }
>			}
>		    }
>
>
>
>This ends up fetching the value for {KEY} by calling
>   Perl_hv_fetch_ent
>with the 'lval' flag true, which makes it appear to be an assignment
>to that key, which is confusing me....
>
>Thanks,
>	Jeffrey
-- 
Nick Ing-Simmons
http://www.ni-s.u-net.com/


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About