No such thing as a small change | |
PerlMonks |
Re: Re: Sometimes it's in Void Contextby Ovid (Cardinal) |
on May 31, 2002 at 23:32 UTC ( [id://170858]=note: print w/replies, xml ) | Need Help?? |
Heh :) Even though your answering a totally different question, it does raise another issue. Why are the following three cases treated differently?
Ignoring, for the moment, the "Useless use of constant in void context" warnings, how does Perl know that the first use of [ 3,2,1 ] is to generate a reference to an anonymous array from a list, while the second example doesn't reduce to this:
We have the same issue with the third example recognizing that [ 3,2,1 ] is to be used as a list of array indices for the slice. This behavior should is difficult to keep straight:
Why doesn't that just assign "cat" to the first element of @lines? My assumption is that it is because the square brackets are performing a subtle double-duty. In this example:
the square brackets are being used to indicate an array element. In another example:
the square brackets are being used to create a reference to an anonymous array and constructs the anonymous array from a list. Keeping things straight can be a major headache, which is why I'm glad Perl does it for me :) Cheers, Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
In Section
Seekers of Perl Wisdom
|
|