Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: compare always true in grep

by crashtest (Curate)
on Oct 24, 2014 at 18:52 UTC ( #1104901=note: print w/replies, xml ) Need Help??


in reply to compare always true in grep

My 5.18.2 on Linux dies the same way. B::Deparse shows this interpretation of your if statement:

if (grep((0 + $_ >= 99999999)), @times) {
Note the parentheses. That is, you have a scalar comma expression with the grep and the @times array, which evaluates to @times. The grep is evaluating the expression 0 + $_ >= 9999999 on an empty list, but that's irrelevant.

Adding the parentheses properly works:

if (grep (((0 + $_) >= 99999999), @times)) { ... # prints: Times: 1 2 3 4

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2020-05-26 13:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (150 votes). Check out past polls.

    Notices?