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

Re: confused: string and number comparison

by wwe (Friar)
on Mar 23, 2011 at 15:07 UTC ( #895011=note: print w/replies, xml ) Need Help??

in reply to confused: string and number comparison

Thank you for your answers. As lostjimmy and moritz already told the problem could be solved easily by doing string comparison. I think my problem was that perl turns a string which doesn't represent a number to zero for numerical comparison as johnqq stated.
  • Comment on Re: confused: string and number comparison

Replies are listed 'Best First'.
Re^2: confused: string and number comparison
by dsheroh (Prior) on Mar 24, 2011 at 10:35 UTC
    Note that this is not unique to Perl. Pretty much every language since C (and probably going back even further) will treat non-numeric strings as 0 when asked to treat them as numbers. Your problem is that you explicitly asked Perl to do a numeric comparison (by using ==) when that wasn't what you actually wanted.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://895011]
[Discipulus]: here spring has sprung, so the warm is available without holidays..
[Discipulus]: Oh I got a (small but better than nothing) salary increase!! beer for all!
[cavac]: Not sure if it's only my connection, but seems rather slow to respond today.
[cavac]: Could some of you just log in for a second and check, for example, the tail daemon logfile?

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2017-02-22 08:57 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (325 votes). Check out past polls.