##
use vars qw/$opt_h $opt_f $opt_d/;
####
{
my %opt;
getopts("hf:d:") || die HELP();
sub opt_h { exists $opt{h} ? 1 : 0 }
sub opt_f { exists $opt{f} ? 1 : 0 }
sub opt_d { exists $opt{d} ? 1 : 0 }
}
if( opt_h ) {
...
}
if( opt_j ) { # compile time error
...
}
####
sub opt_f {
if( not exists $opt{f} ) {
0
}
elsif( not defined $opt{f} ) {
'default-value'
}
else {
$opt{f}
}
}
####
(my $new = $old) =~ s/foo/bar/;