Hello TonyNY,
You should always code with
use strict; use warnings;
at the head of your script, in which case, if $ARGV[2] is undefined, the statement chomp $id; will generate a warning. So the correct logic is:
use strict; use warnings; my ($pkgname, $envname, $id) = @ARGV; if (defined $id) { chomp $id; print "Third argument: >$id<\n"; } else { print "No third argument\n"; }
BTW, these statements:
chomp; s/^\s+|\s+$//g; # trim spaces
operate on the default variable $_, which is not initialised in the code snippet you show.
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re: Make command line argument optional
by Athanasius
in thread Make command line argument optional
by TonyNY
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |