abstracts has asked for the wisdom of the Perl Monks concerning the following question:
Here is something I stumbled across:
This error occurs only if the program is in a file (ie perl -e 'print "hello" if "0"' works as advertized). Could anybody enlighten me for the reason for this seemingly strange behavior?print "hello" if 1; # prints hello print "hello" if 0; # doesn't print anything print "hello" if "1"; # prints hello again print "hello" if "0"; # Useless use of a constant in void context at ./test.pl line 3.
PS: ("0" and print "hello") fails for the exact reason since perl translates (print "hello" if "0") to ("0" and print "hello") at compile time if I remember the perl parser correctly.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(crazyinsomniac) Re: if "0"
by crazyinsomniac (Prior) on Apr 22, 2002 at 09:19 UTC | |
|
Re: if "0"
by blakem (Monsignor) on Apr 22, 2002 at 08:49 UTC | |
by Dog and Pony (Priest) on Apr 22, 2002 at 19:56 UTC |