Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: grep flip flop (range operator)

by Neighbour (Friar)
on Sep 13, 2012 at 06:42 UTC ( #993380=note: print w/ replies, xml ) Need Help??


in reply to grep flip flop (range operator)

What are you expecting to get with 1 .. /Q/?
The following code prints nothing as well:

use Data::Dump; Data::Dump::dd(1 .. /Q/);
If your match-list is empty, nothing matches, and nothing is printed.
However, this does not explain why the last command *does* print something :)

Edit: Upon further reading, it looks like the range operator isn't parsed in scalar context, as the following does print something: perl -le " print for grep scalar 1 .. /Q/, @ARGV " a b c Q r s

Output: a b c Q r s


Comment on Re: grep flip flop (range operator)
Select or Download Code
Re^2: grep flip flop (range operator)
by Anonymous Monk on Sep 13, 2012 at 07:04 UTC

    Edit: Upon further reading, it looks like the range operator isn't parsed in scalar context, as the following does print something: perl -le " print for grep scalar 1 .. /Q/, @ARGV " a b c Q r s

    I use    perl -MO=Deparse,-p   what you have is  (scalar(1) .. /Q/)

    you need  scalar( 1 .. /Q/ ) to get nothing :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (14)
As of 2014-07-23 14:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (145 votes), past polls