[Mpls-pm] Dereferencing complicated things...

Eric Estabrooks eric at urbanrage.com
Wed Dec 7 06:14:53 PST 2005


Ken Williams wrote:

>Double correction, it should have been:
>
>   $a = {b => [1,2,3]}
>
>The solution you're looking for is:
>
>   @result = @{ $b->{b} };
>  
>
I hate to disagree but you need to do a double dereference on $b since 
its a ref to a scalar that holds a ref to a hash.  If you want to just 
have a single dereference then it would be a sort of combination of the 
two corrections.

%a = (b => [1,2,3]);
$b = \%a;
@c = @{ $b->{b} };
$val = $b->{b}[1];

Eric

>The rule is that following the '@' character must either be the name of 
>an array (such as "result" above, or a simple scalar such as $x (e.g. 
>@$x) that holds an array reference, or brackets that evaluate to a name 
>or an array reference.
>
>If you're running under "strict" mode, no evaluation is allowed in the 
>latter "name" case, it must be a literal name (e.g. @{ result }).
>
>The following code demonstrates a few ways of accessing the same array:
>
>  @x = (1..10);
>  print @x;  # Literal
>  $y = \@x;
>  print @$y;  # Hard reference
>  print @{\@x}; # Hard reference
>  print @{"x"}; # Soft reference
>  print @{lc("X")}; # Soft reference
>
>Of course, if you want to address individual elements of your $b->{b} 
>structure, you can just use $b->{b}[0], $b->{b}[1], etc.
>
>  -Ken
>
>On Dec 6, 2005, at 9:41 PM, Dave Dash wrote:
>
>  
>
>>Actually correction that should be
>>
>>%a = {b => [1,2,3]}
>>
>>On 12/6/05, Dave Dash <dd at davedash.com> wrote:Let's say I have a hash:
>>    
>>
>>>$a = {b=>(1,2,3)}
>>>
>>>and
>>>
>>>$b = \$a;
>>>
>>> Is there a way given $b->{b} to dereference that into the array that 
>>>is (1,2,3) ?
>>>
>>>Currently I end up doing a lot of annoying steps, but it'd be nice if 
>>>something like @($b->{b}) would work...
>>>
>>>-- 
>>>Dave Dash
>>>612.670.0621
>>>3555 Fremont Ave S, Mpls, MN 55408
>>>http://citybikemap.com/
>>>http://davedash.com/
>>>AIM: davesdash
>>>      
>>>
>>-- 
>>Dave Dash
>>612.670.0621
>>3555 Fremont Ave S, Mpls, MN 55408
>>http://citybikemap.com/
>> http://davedash.com/
>>AIM: davesdash_______________________________________________
>>Mpls-pm mailing list
>>Mpls-pm at pm.org
>>http://mail.pm.org/mailman/listinfo/mpls-pm
>>    
>>
>
>_______________________________________________
>Mpls-pm mailing list
>Mpls-pm at pm.org
>http://mail.pm.org/mailman/listinfo/mpls-pm
>  
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3174 bytes
Desc: S/MIME Cryptographic Signature
Url : http://mail.pm.org/pipermail/mpls-pm/attachments/20051207/eeb3f650/smime.bin


More information about the Mpls-pm mailing list