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.
In reply to if "0" by abstracts
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |