[bcn-pm] Getopt::Long i funcions per una mateixa opció
Alex Muntada
alexm a alexm.org
dim feb 7 08:54:13 PST 2012
+ Alex Muntada <alexm a alexm.org>:
> 'list=s' => sub { exists $opt{$_[0]}{$_[1]} && $opt{$_[0]}{$_[1]}->(); }
Perquè després diguin que Perl no és llegible, ho pinto en maco:
GetOptions(
'list=s' => \&opt_list,
'help|?' => \&opt_help,
);
sub opt_list {
my ( $list, $cmd ) = @_;
return unless exists $opt{$list}{$cmd};
my $sub_ref = $opt{$list}{$cmd};
$sub_ref->();
}
sub opt_help {
print "Nop\n";
}
Com diem a can Perl, hi ha més d'una manera de fer-ho ;-)
Salut i Perl!
--
Alex Muntada <alexm a alexm.org>
http://alexm.org/
Més informació sobre la llista de correu Barcelona-pm