in reply to Make command line argument optional
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Make command line argument optional
by TonyNY (Beadle) on Jul 10, 2018 at 20:20 UTC | |
by huck (Prior) on Jul 10, 2018 at 21:37 UTC |