develooper Front page | perl.perl6.language | Postings from September 2005

Re: for $arrayref {...}

Thread Previous
From:
Luke Palmer
Date:
September 2, 2005 01:25
Subject:
Re: for $arrayref {...}
Message ID:
7ca3f0160509020125378c7665@mail.gmail.com
On 9/2/05, Juerd <juerd@convolution.nl> wrote:
> Luke Palmer skribis 2005-09-01 23:43 (+0000):
> > I would probably say that scalars never automatically dereference.
> > It's lists and hashes that automatically dereference/enreference.
> 
> arrays

Yes, arrays, right.

> > That is, everything is a scalar, really, but if you have an @ or a %
> > on the front of your variable, that means that you flatten yourself
> > into specific kinds of contexts.
> 
>     sub foo (@bar) { ... }
> 
>     foo $aref;
> 
> Here $aref is dereferenced because of the Array context. The scalar
> can't do this by itself, of course.

No, my view is that $foo and @foo are really the same kind of thing. 
They're both references to lists (yes, lists).  So binding @bar :=
$aref is not doing anything special, it's just like binding two
scalars.  The only thing that makes @bar different from $aref is that
in list context, @bar flattens out the list it's holding whereas $aref
doesn't.

Luke

Thread Previous


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