I am passing the command line arguments to a Perl script and retrieving it via ARGS[0].
perl <perlscript.pl> windows IE.
I would like to give keywords to the values mentioned above.
perl <perlscript.pl> -os windows -browser IE -instance 2.
There might be times where instance might or might not be present. How do I go about handling this in my Perl script?
Use Getopt::Long and store your options in a hash:
use warnings;
use strict;
use Getopt::Long qw(GetOptions);
my %opt;
GetOptions(\%opt, qw(
os=s
browser=s
instance=i
)) or die;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With