Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: next unless - doesnt work?

by sweepy838 (Acolyte)
on Apr 28, 2012 at 15:16 UTC ( #967820=note: print w/ replies, xml ) Need Help??


in reply to Re: next unless - doesnt work?
in thread next unless - doesnt work?

ah i solved the problem using ne instead of eq :) and for some reason != didnt do the job but ne did.. strange?


Comment on Re^2: next unless - doesnt work?
Re^3: next unless - doesnt work?
by stevieb (Hermit) on Apr 28, 2012 at 15:35 UTC

    Not strange ;)

    != and == are for numeric context comparisons where eq/ne are for evaluating strings.

    Your original post didn't show any code relating to evaluations, so I, nor anyone else have any idea how this was part of your problem in the first place.

      not strange? when you think about it, it is strange! :)

        "Strange" is relative. If you come from another programming language, say PHP, then it may seem strage at first. But when you think about it, it actually makes perfect sense, since it makes the distinction between number- and string comparisons much clearer.
        Although, if you really wanted to, you could probably overload == to do string comparisons as well.

        ~Thomas~

        Not strange if you came from Unix shell, which also uses different operators for numeric versus string comparison. :)

        Some background as to why Perl has string and numeric operators can be found in Modern Perl in the "Numeric, String, and Boolean Context" section on page eight:

        In exchange for not having to declare (or at least track) explicitly what type of data a variable contains or a function produces, Perl offers specific type contexts that tell the compiler how to treat a given value during an operation ...

        The eq operator treats its operands as strings by enforcing string context on them. The == operator imposes numeric context ...

        Perl will do its best to coerce values to the proper type depending on the operators you use. Be sure to use the proper operator for the type of context you want.

        This issue was discussed in gory detail a month ago in: Definition of numerically equal and rationale for 'you' == 'me'.

        I don't get it? Why is it strange?

Re^3: next unless - doesnt work?
by Anonymous Monk on Apr 28, 2012 at 15:36 UTC

    and for some reason != didnt do the job but ne did.. strange?

    Not at all. One is for numbers, the other for strings. You would've gotten a warning if you had use warnings on.

Re^3: next unless - doesnt work?
by brx (Pilgrim) on Apr 28, 2012 at 15:42 UTC
    String vs numerical
      my bad :( lol
Re^3: next unless - doesnt work?
by ww (Bishop) on Apr 28, 2012 at 17:13 UTC
    Not at all strange: ne is used for alphas; != for numbers.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2014-10-26 02:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (149 votes), past polls