Re: qw(l i s t) vs (l, i, s, t)

[email protected] (Yitzchak Scott-Thoennes)
Newsgroups gmane.comp.lang.perl.fun
Organization bs"d
Message-ID <i+RH/[email protected]>
On Tue, 22 Jul 2003 03:48:53 +0200, [email protected] wrote:
>
>Could someone please explain what is happening here?
>I came across it, and had a hard time trying to figure out what was 
>going on.

When you use an array in scalar context (e.g. scalar(@ARGV)==foo, or even
just @ARGV==foo), it gives the number of elements in the array (either
2 or 3 in your examples).

When you use a comma-operator in scalar context (e.g. (2,3)) it throws
away the left operand and returns the right one.

qw() should act just like a comma'd list, so scalar(qw(2 3)) should be
3.  You aren't seeing this, so I suspect you to be using an extremely
old version of perl where qw() didn't work as well.  If you upgrade to
5.005_55 or higher you should see qw() acting better.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.