Please take a look at the piece of code below:
And some sample runs and my questions are list below in red:
Many thanks!!
Code:
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
my ($debug, $emailAddr, $fussy, $fussier);
GetOptions( [b]# This is line 8[/b]
"d" => \$debug,
"e=s" => \$emailAddr,
"fussy" => \$fussy,
"fussier" => \$fussier,
) || die;
if($fussy) {
print "\$fussy = $fussy\n";
}
if($fussier) {
print "\$fussier = $fussier\n";
}
if($debug) {
print "\$debug = $debug\n";
}
if($emailAddr) {
print "\$emailAddr = $emailAddr\n";
}
print "$0 exit...\n";
exit;
And some sample runs and my questions are list below in red:
Code:
% ./tt.pl -d
$debug = 1
./tt.pl exit...
% ./tt.pl -e
Option e requires an argument
Died at ./tt.pl line 8.
% ./tt.pl -e -d
$emailAddr = -d [b][COLOR=red]<-- This is a bug. How to fix it?[/color][/b]
./tt.pl exit...
% ./tt.pl -fussy
$fussy = 1
./tt.pl exit...
./tt.pl -ff
Unknown option: ff
[b]Died at ./tt.pl line 8.[/b]
% ./tt.pl -fussier
$fussier = 1
./tt.pl exit...
% ./tt.pl -fussi
$fussier = 1 [b][COLOR=red]<-- How can this happen? I'd expect to see the error: Unknown option: fussi[/color][/b]
./tt.pl exit...
Many thanks!!