Skip to content

Instantly share code, notes, and snippets.

@alexm
Created February 6, 2012 15:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexm/1752738 to your computer and use it in GitHub Desktop.
Save alexm/1752738 to your computer and use it in GitHub Desktop.
Getopt::Long subs via hash
#!/usr/bin/env perl
use strict;
use warnings;
use 5.010;
use Getopt::Long;
sub list_postinstall {
say "postinstall: <@_>";
}
sub list_distros {
say "distros: <@_>";
}
my %opt = (
list => {
postinstall => \&list_postinstall,
distros => \&list_distros,
},
);
GetOptions( 'list=s%' => sub { $opt{ $_[0] }{ $_[1] }->( $_[2] ) } );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment