[Mpls-pm] Dereferencing complicated things...

Dave Dash dd at davedash.com
Wed Dec 7 08:26:36 PST 2005


Well I guess I was just not sure of the syntax @{} being able to dereference
something like a $sth->selectall_arrayref({}) in DBI.pm.  But now i've saved
several unnecessary steps by learning that.

On 12/7/05, Michael J. Freeman <mfreeman at netcogov.com> wrote:
>
> Why do you want to copy that hash to $b though? Why not just dereference
> $a? I
> use to do this myself a lot before I got the hang of referencing and then
> got
> bitten by it.
>
> On Wednesday 07 December 2005 08:14, Eric Estabrooks wrote:
> > 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
>
> --
> Michael J. Freeman
> NMS Development
> Netco Government Services, Inc.
> --
> The world is full of willing people, some willing to work, the rest
> willing to
> let them.
>         -- Robert Frost
>
>
>
> _______________________________________________
> Mpls-pm mailing list
> Mpls-pm at pm.org
> http://mail.pm.org/mailman/listinfo/mpls-pm
>
>
>


--
Dave Dash
612.670.0621
3555 Fremont Ave S, Mpls, MN 55408
http://citybikemap.com/
http://davedash.com/
AIM: davesdash
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/mpls-pm/attachments/20051207/e73a6b65/attachment.html


More information about the Mpls-pm mailing list