Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: confused: string and number comparison

by lostjimmy (Chaplain)
on Mar 23, 2011 at 14:35 UTC ( [id://895008]=note: print w/replies, xml ) Need Help??


in reply to confused: string and number comparison

Why not just do a string equality comparison for both? You won't have the warning, and comparing '0' to 0 will give you the desired outcome.

Update: Just checking the value's truthiness should also suffice.

my @comparisons = ('0', 0, 1, '', '0 but true', 'abcd'); for (@comparisons) { if ($_) { print "keep [$_]\n"; } else { print "discard [$_]\n"; } }

Replies are listed 'Best First'.
Re^2: confused: string and number comparison
by dsheroh (Monsignor) on Mar 24, 2011 at 10:32 UTC
    Just checking the value's truthiness should also suffice.
    No, it won't. OP says that he's looking for cells containing either the single digit 0 or a single space, which is a true value. If he were looking for 0 or an empty string, then just checking truthiness would work, though.
      And that's what I get for not reading the spec thoroughly...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-18 10:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found