in reply to Using number "0" as an input argument
I know I can validate that the input argument was there via the following bit of code:
chomp(my $in1 = $ARGV[0] || ''); if (defined $in1) { #Validate; }
Have you ever encountered a case where $in1 was not defined?
Maybe you want to directly check the number of arguments in @ARGV or look at what the || operator does?
Maybe the following code helps you analyze what happens better:
my $in1 = $ARGV[0] || 'user-did-not-pass-an-argument'); print $in1;
Run the above code with
perl -w myscript.pl # no argument perl -w myscript.pl "" # empty argument perl -w myscript.pl 0 # zero argument perl -w myscript.pl something-else # other argument
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using number "0" as an input argument
by Doozer (Scribe) on Sep 22, 2015 at 09:44 UTC | |
by RonW (Parson) on Sep 22, 2015 at 17:37 UTC | |
by SuicideJunkie (Vicar) on Sep 22, 2015 at 14:54 UTC |