Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: how to write script usage sub routine for the perl file? the dynamic duo with Pod::Usage

by Discipulus (Abbot)
on Apr 03, 2017 at 07:54 UTC ( #1186789=note: print w/replies, xml ) Need Help??


in reply to how to write script usage sub routine for the perl file?

Hello perlanswers and welcome to the monastery and to wonderful world of Perl!

There are many way to do it but I found the following particulary useful and versatile: The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan!

Infact Pod::Usage can semplfy a lot such part of a program: it can shows sections of your choice of the POD embed in the program (I'm used to put the POD after the __DATA__ token), it has the ability to modify the exit value with the useful NOEXIT feature.

The module can semplify a lot the help and manual commandline options; let's see it's recommendend usage:

use strict; use Pod::Usage; use Getopt::Long; ## Parse options my %opt; GetOptions(\%opt, "help|?", "man", "flag1") || pod2usage(2); pod2usage(1) if ($opt{help}); pod2usage(-exitval => 0, -verbose => 2) if ($opt{man}); ## Check for too many filenames pod2usage("$0: Too many files given.\n") if (@ARGV > 1);

L*

There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
  • Comment on Re: how to write script usage sub routine for the perl file? the dynamic duo with Pod::Usage
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1186789]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2021-02-27 15:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?