SPUG: Shouldn't this work?

ced at carios2.ca.boeing.com ced at carios2.ca.boeing.com
Thu Nov 29 15:23:12 CST 2001


> The qw operator creates an array, not an arrayref. The qw operator is
>  magical in that you can use a delimiter that is part of an open/close
>  pair, like {}, [], (), or a 'unary' delimiter, like $$, %%, ##, //, ||,
>  whatever. They all mean the same thing.

Just an slight term clarification (to remind myself mostly) but 
"array" may be a confusing word in this context. 

The qw operator creates a list rather than an actual Perl array. 
In other words, if an actual array had been created the $aref below 
would have been an array in scalar context and $aref would be 4 and 
there wouldn't have been a -w warning. 

Instead, the original:   my $aref = qw[one two three four]; 
is equivalent to:        my $aref = ("one","two","three","four");

$aref now becomes "four" and you see the warnings:

  "Useless use of a constant in void context"

because the initial list members are just being discarded by by
the comma operator.  

Rgds,
--
Charles DeRykus

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://zipcon.net/spug/





More information about the spug-list mailing list