I've just noticed a strange behavior of perl5 (5.10.0) when I passed 0 as the command-line argument to a script, which assigns it to a variable. The problem I encountered is that if I give the variable a default value in my script which is greater than 0, say 1, then I can pass any value except 0 to override the default value 1.
Following is the code of 'test.pl' I used:
#!/usr/bin/perl -w
my $x = shift || 1;
print "x is $x\n";
Following are the commands and ouputs when I tested it:
$ ./test.pl 2
x is 2
$ ./test.pl 0
x is 1
I'd appreciate if anyone can shed light on this. Thanks. wwl