For program (not library a.k.a. module) code. Provides either succinct or verbose "help" (usage) messages when program code includes self-documenting POD.
use Pod::Usage 'pod2usage'; BEGIN { my $max_valid_args = <FILL IN FOR YOUR PROGRAM> ; my $min_valid_args = <FILL IN FOR YOUR PROGRAM> ; my( $argC,$argN ) = (0 + @ARGV , $ARGV[$#ARGV] ); if( grep { $_ eq lc($argN) or $_ eq substr lc($argN)=>1 } qw/ -h -u -man -help -usage / ) { pod2usage(-verbose => 2) } elsif ($argC < $min_valid_args or $argC > $max_valid_args ) { pod2usage(1) } }

This snippet is a kwik-N-eezy way to provide rudimentary yet flexible user help messages for your Perl program. It is not strictly necessary to wrap it in a BEGIN sub block, so if you don't like that, use it bare. It incurs some small additional overhead to do like shown here. I don't care about that and like the scoping confinement provided for the logic, as well as the chance to prevent loading some large module I'm use'-ing if all the user wanted was a usage hint.

The excellent Getopt::* module facilities are not employed here to do the argument parsing. That keeps this snippet a lightweight and brief way of providing help messages. I am in no way discouraging people from using Getopt::*, quite the contrary. I urge you to use that reusable and well-engineered solution. However, if, like me, you prefer to keep the source for simple Perl programs looking very, er, simple, then try this snippet out.

The flexibility mentioned comes in because the user can type either one-hyphen - or two-hyphen -- forms of multi-letter switches and get the response they expect.

Soren A / somian / perlspinr / Intrepid

-- 
Try my n.y.p.m.blue Perl Monks CSS Theme
(edit "On-Site CSS Markup" in your User Settings)