in reply to Using Getopt::Long to call subroutines
use strict; use warnings; my %dispatch = ( one => \&sub1, two => \&sub2, three => \&sub3, ); my $arg = shift @ARGV; if (defined $arg && exists $dispatch{$arg}) { $dispatch{$arg}->(); } else { print "Usage: $0 [-command]\n"; print "Available commands:\n"; print " -$_\n" for sort keys %dispatch; } sub sub1 { print "sub one"; } sub sub2{ print "sub two"; } sub sub3 { print "sub three"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using Getopt::Long to call subroutines
by chinamox (Scribe) on Oct 22, 2006 at 04:10 UTC | |
by imp (Priest) on Oct 22, 2006 at 04:19 UTC |