in reply to Getopt::Long subroutine usage
Maybe this example will help:
#!/usr/bin/perl use strict; use warnings; use Getopt::Long; $| = 1; my $blah = 0; if ( scalar( grep( /^-/, @ARGV ) ) ) { GetOptions( 'blah' => sub { $blah = ( $blah ? 0 : 1 ); }, 'help' => \&help ); } printf <<RESULTS, $blah; Blah: %d RESULTS sub help { print <<HELPTEXT; $0 [-blah] [-help] -blah - do something -help - display this help text HELPTEXT exit; }
In this contrived example, using the -help option will execute the &help routine, while the -blah option will execute the anonymous subroutine (which in this contrived example flips the value of $blah between true and false).
Hope that helps.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getopt::Long subroutine usage
by rockneybot (Novice) on Jan 05, 2005 at 02:36 UTC | |
by graff (Chancellor) on Jan 05, 2005 at 06:02 UTC | |
by rockneybot (Novice) on Jan 05, 2005 at 08:21 UTC | |
by Solo (Deacon) on Jan 05, 2005 at 15:40 UTC | |
by rockneybot (Novice) on Jan 05, 2005 at 19:41 UTC |