[Mpls-pm] Dereferencing complicated things...

Ken Williams ken at mathforum.org
Tue Dec 6 21:09:35 PST 2005


Double correction, it should have been:

   $a = {b => [1,2,3]}

The solution you're looking for is:

   @result = @{ $b->{b} };

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



More information about the Mpls-pm mailing list