Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line arguments with keywords

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?

like image 724
Leo Avatar asked Feb 06 '26 21:02

Leo


1 Answers

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;
like image 182
toolic Avatar answered Feb 09 '26 11:02

toolic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!