nimdokk has asked for the wisdom of the Perl Monks concerning the following question:

I've come across an interesting twist. We were sent a Perl script by our vendor and when I tried to run it, it choked on one particular line.

This is what I got for an error message:

Bareword found where operator expected at prog.pl line 1544, near ") NE" (Missing operator before NE?) syntax error at prog.pl line 1544, near ") NE " syntax error at prog.pl line 1548, near "else" Execution of dni aborted due to compilation errors.

This is what they are trying:

while (($var1 = index ($var2, $var3)) NE -1 )
Now, I didn't fully check things out and concluded that they had meant to do != instead of NE. I didn't realize that "ne" was a string comparison, not a numeric even though it looked like they were trying to do a numeric comparison. I substituted in != and everything ran fine. However, I had an email from tech support that the version of Perl I was looking at (ActivePerl 5.8.0) didn't like the "NE" and that I should put in "ne" instead. I did this and it worked just fine. The only versions of Perl that I've looked at have been 5.8.0 (Windows and Unix, same errors with the "NE"). I checked through the Camel book and only find "ne" not "NE." Is there really a difference between the two? or am I losing it? Is there something perhaps in later builds of 5.8.0 that would account for this issue? Any thoughts anyone?


"Ex Libris un Peut de Tout"

Replies are listed 'Best First'.
Re: Problem with case sensitivity?
by eserte (Deacon) on Apr 06, 2004 at 17:55 UTC
    perldoc perldelta says:
    * The long deprecated uppercase aliases for the string comparison operators (EQ, NE, LT, LE, GE, GT) have now been removed.
Re: Problem with case sensitivity?
by ambrus (Abbot) on Apr 06, 2004 at 18:02 UTC

    NE was an obsolate alias for ne, which is removed completely from newer perls. You should just use ne if you mean string comparison, and != for numbers; in this example either are the same.

    Perldoc perl570delta documents this change:

    Incompatible Changes
    • The long deprecated uppercase aliases for the string comparison operators (EQ, NE, LT, LE, GE, GT) have now been removed.

    (Note also stdout, which is an alias for STDOUT, but that is still supported. And the same for STDIN, STDERR)

Re: Problem with case sensitivity?
by Fletch (Bishop) on Apr 06, 2004 at 18:27 UTC

    Once again underscoring the importance of -w or use warnings;.

    freebie:~ 730> perl -we 'print "Foo" if "a" NE "B"' Use of NE is deprecated at -e line 1. freebie:~ 731> perl -v This is perl, v5.6.1 built for i386-freebsd [...]
Re: Problem with case sensitivity?
by halley (Prior) on Apr 06, 2004 at 17:49 UTC
    The whole Perl language is case-sensitive.

    You can't use NE for ne, just like you can't use WHILE () for while () or USE parse::recdescent for use Parse::RecDescent.

    --
    [ e d @ h a l l e y . c c ]

Re: Problem with case sensitivity?
by Aragorn (Curate) on Apr 06, 2004 at 19:53 UTC
    Your first reaction to use != was the right one. Although the ne works, it's not optimal, because the return value of index (a number) and the -1 are first converted to strings, and then compared. This is much slower than comparing the actual numbers.

    Arjen

[OT] Re: Problem with case sensitivity?
by saintbrie (Scribe) on Apr 06, 2004 at 22:54 UTC
    Just wanted to point out that if the $[ (index of the first character in a substring) variable has been changed, you won't get the answer you are expecting. Compare index values to ($[ - 1) to avoid the problem.
Re: Problem with case sensitivity?
by nimdokk (Vicar) on Apr 07, 2004 at 09:46 UTC
    Thanks everyone who replied. It really makes me wonder what kind of geniuses are out there some days. Especially when they claim to be using a newer build of 5.8.0 than we are. Oh well, I've got bigger things to worry about, but it makes me a little nervous about the rest of their code as well. :-)


    "Ex Libris un Peut de Tout"