SPUG: Shouldn't this work?

David Dyck dcd at tc.fluke.com
Thu Nov 29 14:54:45 CST 2001


On Thu, 29 Nov 2001 at 12:14 -0800, Martin, Asa <asa.martin at attws.com> wrote:

> Am I missing something, or shouldn't this syntax be valid to create a
> reference to an anonymous array:
>
> $ cat /tmp/a
> #!/usr/bin/perl -w
> use strict;
>
> my $aref = qw[one two three four];

Change this to
   my $aref = [ qw[one two three four] ];

> if (ref($aref) eq 'ARRAY') {
>    print "yes\n";
> }

Then the script prints yes.

The [] in
 my $aref = qw[one two three four];
are just quoting
       qw/STRING/
               Generalized quotes.  See "Regexp Quote-Like
               Operators" in perlop.

No array reference is created

the outer square braces around the qw()
are what create the reference


 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     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