Processing Command Line Options with PERL - Half-Life (Page 5 of 9 )
In addition to setting Booleans, Getopt::Long.pm also supports processing string and numeric command-line arguments entered by the user. To illustrate how this works, consider the following simple example:
#!/usr/bin/perl
# import module
use Getopt::Long;
# read options
$result = GetOptions ("age=i" => $age);
# print value
if ($age) { print "Input age is $age years"; }
Here's the output:
$ ./script.pl --age=89
Input age is 89 years
Here, the "i" data type specifier tells Getopy::Long.pm to expect an integer value after the option name. You can also use "s" for strings, as in the following example:
#!/usr/bin/perl
# import module
use Getopt::Long;
# read options
$result = GetOptions ("name=s" => $name);
# print value
print "Input name is $name";
Here's the output:
$ ./script.pl --name=John
Input name is John
Next: Getopt::Long.pm >>
More Perl Articles
More By icarus, (c) Melonfire