in reply to Unexpected effect of -w with undef

You are giving Perl the code w to execute and the filename if (undef() eq undef()) {print "true" }else{ print "false"} as an argument to it. You probably wanted to say -we… Most of perl's switches are order sensitive.

strict catches this, FWIW:

$ perl -Mstrict -ew 'if(undef() eq undef()){print "true"}else{print "f +alse"}' Bareword "w" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. $ perl -Mstrict -we 'if(undef() eq undef()){print "true"}else{print "f +alse"}' Use of uninitialized value in string eq at -e line 1. Use of uninitialized value in string eq at -e line 1. true

Makeshifts last the longest.

Replies are listed 'Best First'.
Re^2: Unexpected effect of -w with undef
by DrWhy (Chaplain) on Dec 22, 2004 at 16:37 UTC
    Aw.... Dang!

    /me smacks forehead.

    --DrWhy

    "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

      Hehehehe. I looked at it in befuddlement for a moment as well after I pasted the code in a terminal and it didn't print a thing. Then I went “Oh! Heh, he'll be really embarrassed when he reads the answer.” Don't sweat it though, we all have our moments. :-)

      Makeshifts last the longest.

        What confused me is that undef eq undef is true, I guess indoctrinated by SQL hanDling of NULL I expect it to be undefined or false ... I guess this is not something that will get changed however.

        /J\