in reply to Weird eq behaviour

Because of a trailing \n char ???

From perlop, it says :

Binary "eq" returns true if the left argument is
stringwise equal to the right argument.


So the string should be exactly the same, byte by byte.

Try this :
perl -e 'print "Ok\n" if( "foo\n" eq "foo" )'
this one print nothing ...
perl -e 'print "Ok\n" if( "foo\n" =~ /^foo$/ )'
but this one print Ok !

Replies are listed 'Best First'.
Re: Re: Weird eq behaviour
by Cine (Friar) on Jul 25, 2002 at 13:00 UTC
    Offcourse :(
    I didnt think of this because I tried to print the line after a s/./ord($&)." "/ge, but that doesnt change the newline either... ARG ;)

    T I M T O W T D I
      use the s modifier on the regexp to catch newline chars :
      s Treat string as single line. That is, change "." to match any character whatsoever, even a newline, which normally it would not match.
      s/./ord($&)." "/ges