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

Re: (1,(2,3),4)[2]

Thread Previous | Thread Next
May 26, 2005 02:30
Re: (1,(2,3),4)[2]
Message ID:
Rod Adams skribis 2005-05-26  4:15 (-0500):
> From S02: "Array and hash variable names in scalar context 
> automatically produce references."
> Since [...] produces a scalar arrayref, we end up with an arrayref one 
> both sides of the =.


There is no scalar context on the LHS of the assignment operator.

And, assigning to a reference is impossible, as a reference is a VALUE,
not a VARIABLE (container).

Assigning to a reference thus makes no sense in the same way that
assigning a new value to the number 42 makes no sense. It is possible
with some tricks, but you really shouldn't ever want to do this.

> If I understand Juerd correctly, the logical extension would be to have
>    @m = 5;
> be the same as:
>    @m = list(5);

The RHS of an array assignment is in list context. "list" is an operator
that does nothing more than force list context. In this case, it is
entirely redundant. But, of course, valid.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About