Now, my problem with the code as it is(will change later in post) comes when I try to put 0 as a command line option when excecuting the script.use strict; use warnings; my $baz = 0; my $foo = shift || 1; chomp(my @bar = qw( etc etcetera )); die "Nice Try." if $foo < 1; while($baz < $foo){ $baz += 1; print "$bar(bracket)rand @bar(/bracket) ", "ad infinitum\n"; }
As it is, if you type 0 at the command line, it will still execute, with only one result, as though it had 1 or no option typed at the command line.
I'm guessing it has to do with the nature of the +=, that it will do something even when other commands tell it not to.
I did find a workaround, almost by accident.
Change || to or. However, if you use the default by not typing in an option, it will give this error:
Use of uninitialized value in numeric lt (<) at footest.pl line 9. Nice try. at footest.pl line 9.
Now, I tried a workaround, by changing "shift or 1," to "shift or die." This sort of works, but what happens is that, 1. You have to type a command line option or it will die, and more interestingly, 2. if you type 0 at the command line, it will give the error message for the "shift or die" line, rather than the other die message.
I just checked it by changing the second die line to < 2 and got the error messages like this:
perl footest.pl 1
Nice try. at footest.pl line 9.
perl footest.pl 0
Died at footest.pl line 6.
perl footest.pl -1
Nice try. at footest.pl line 9.
So...I'm thinking that 0 has some sort of special property here, that's making it act that way. Perhaps, as a guess, having to do with it's characteristic as being one of the things that means false?
20050102 Edit by ysth: code and p tags
In reply to fun(?) with += by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |