in reply to Combining two scripts with a command line switch?
#!/usr/local/bin/perl -w use Getopt::Long; my ($hello,$goodbye); # option switches GetOptions ( "hello" => \$hello, "goodbye" => \$goodbye, ); if ($hello) { print "Hello world\n"; } if ($goodbye) { print "Goodbye!\n"; }
# use full options > perl test.pl --hello --goodbye Hello world Goodbye!
# use abbreviation > perl test.pl -h Hello world
Getopt::Long can also handle a variety of different option types, with or without arguments etc. See the documentation.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Combining two scripts with a command line switch?
by Seventh (Beadle) on Dec 13, 2004 at 18:12 UTC | |
by Joost (Canon) on Dec 13, 2004 at 18:18 UTC | |
by rev_1318 (Chaplain) on Dec 14, 2004 at 11:13 UTC |