Created
November 29, 2012 17:09
-
-
Save radaniba/4170447 to your computer and use it in GitHub Desktop.
I've seen a lot of question of perl programmers asking how to handle arguments for their script, here is an example snippet you can customize for your needs, cheers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #-------------------------------------------------------------------------- | |
| # handle the command line arguments | |
| # | |
| if ( $#ARGV == -1) | |
| { | |
| &usage; | |
| exit 0; | |
| } | |
| while (@ARGV) | |
| { | |
| $argument = shift(@ARGV); | |
| if ($argument eq "-HELP" || $argument eq "-H") | |
| { | |
| &usage; | |
| exit 0; | |
| } | |
| elsif ($argument eq "-file" || $argument eq "-f") | |
| { | |
| $file = shift(@ARGV); | |
| } | |
| elsif ($argument eq "-verbose" || $argument eq "-v") | |
| { | |
| # input data come live from the specified htget output file. Faster. | |
| $verbose = 1; | |
| } | |
| elsif ($argument eq "-DEBUG") | |
| { | |
| $DEBUG_LEVEL = shift(@ARGV); | |
| } | |
| elsif ($argument eq "-DOCUMENT" || $argument eq "-D") | |
| { | |
| &document; | |
| exit 0; | |
| } | |
| elsif ($argument eq "-ABOUT" || $argument eq "-A") | |
| { | |
| &about; | |
| exit 0; | |
| } | |
| elsif ($argument eq "-REL_NOTES" || $argument eq "-R") | |
| { | |
| &rel_notes; | |
| exit 0; | |
| } | |
| else | |
| { | |
| print "ERROR: unknown argument '$argument'.\n"; | |
| &usage; | |
| exit 0; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment