Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Precedence of qw

by doc_faustroll (Scribe)
on Apr 04, 2006 at 17:03 UTC ( #541188=note: print w/ replies, xml ) Need Help??


in reply to Precedence of qw

seems like you are getting too complicated and choosing the wrong operator here. Tell me why you want to use the qw operator?
from perldoc perlop

qw/STRING/ Evaluates to a list of the words extracted out of STRING, using embedded whitespace as the word delimiters. It can be under- stood as being roughly equivalent to: split( , q/STRING/); the differences being that it generates a real list at compile time, and in scalar context it returns the last element in the list.

So why in the heck would you use this operator on one value in the middle of a push statement. The interpreter does its best but you are making it hemmorage here. use the q operator.

#This works: push @array, q(X) x 2; print @array, "\n";


Comment on Re: Precedence of qw
Download Code
Re^2: Precedence of qw
by eff_i_g (Curate) on Apr 04, 2006 at 17:14 UTC
    doc,

    I was looking at qw() for maintenance purposes; so some one would be able to type in a new word if need be instead of the extra comma, quote, quote--Yes, picky, I know. But, again, this is used a lot in Perl to allow for easy modification.

    Your code will not work because q(X) x 2 results in ('XX') not ('X', 'X') as you can see via:
    #!/usr/bin/perl -w use strict; my @array; push @array, q(X) x 2; print join ' - ', @array, "\n"; @array = (); push @array, ('X') x 2; print join ' - ', @array, "\n";
      (q(X)) x 2 would give ('X', 'X')
      aha. I see. thanks.
      although if you are using single words? I can see the need for a list context with a list of things.

      anyhoo, glad the fix is in release, and my compliments to you for a clever username. one of the more clever ones on perlmonks.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://541188]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (20)
As of 2014-07-11 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (232 votes), past polls