SPUG: last index array reference's referent

Michael R. Wolf MichaelRWolf at att.net
Mon Jan 22 17:51:36 PST 2007


I didn't believe that this was documented.  I still don't.  But perhaps this
is as close as it gets.  (Put on your Perl glasses, and read between the
lines.)  I can make myself believe that this is what it means, but I'd have
been hard pressed to realize it up front.  Thanks again!

I guess I like it that Perl anticipated my needs here..??!!..


Using References

That's it for creating references. By now you're probably dying to know how
to use references to get back to your long-lost data. There are several
basic methods.


      Anywhere you'd put an identifier (or chain of identifiers) as part of
a variable or subroutine name, you can replace the identifier with a simple
scalar variable containing a reference of the correct type:

          $bar = $$scalarref;
          push(@$arrayref, $filename);
          $$arrayref[0] = "January";
          $$hashref{"KEY"} = "VALUE";
          print $globref "output\n

[... See link for full details]

Michael R. Wolf
    All mammals learn by playing!
        MichaelRWolf at att.net

> -----Original Message-----
> From: spug-list-bounces+michaelrwolf=att.net at pm.org [mailto:spug-list-
> bounces+michaelrwolf=att.net at pm.org] On Behalf Of jerry gay
> Sent: Sunday, January 21, 2007 3:45 PM
> To: Michael R. Wolf
> Cc: spug-list at mail.pm.org
> Subject: Re: SPUG: last index array reference's referent
> On 1/21/07, Michael R. Wolf <MichaelRWolf at att.net> wrote:
> > # Is there a more elegant way to get the equivalent of $#seasons if
> > # all you have is a reference?  Somehting that would do to references
> > # what $# does to arrays....
> >
> sure! use C<$#$seasons>
> perl -Mstrict -Mwarnings -e'my $a=[1,2,3]; print $#$a;'
> 2
> ~jerry
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>      POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>     MEETINGS: 3rd Tuesdays
>     WEB PAGE: http://seattleperl.org/

More information about the spug-list mailing list