1: #!/usr/bin/perl
2:
3: use Pod::Text;
4:
5: &pods unless $name = shift;
6:
7: print "Greetings, $name. I'm quite pleased to meet you.\n";
8:
9: # I use the following little 6-line snippet in almost every script
10: # I write for public consumption. It allows me to use embedded
11: # POD documentation for the script as its usage statement,
12: # saving me the trouble of maintaining separate documentation
13: # and usage statements and allowing me to easily create HTML,
14: # LaTeX, PDF, or whatever kind of documentation for the script
15: # that I like.
16:
17: # It's so trivial, it almost seems silly to post it; however,
18: # I've found it to be quite useful.
19:
20: sub pods {
21:
22: my $message = shift;
23: print "\n$message\n\n" if $message;
24: open(POD,$0) || die "Cannot print help text for $0: $!";
25: Pod::Text->new()->parse_from_filehandle(\*POD);
26: close POD;
27: exit;
28:
29: } # end sub pods
30:
31: __END__
32:
33: =head1 DESCRIPTION
34:
35: hello.pl - A Perl script to print a greeting
36:
37: =head1 USAGE
38:
39: ./hello.pl name
40:
41: where C<name> is your name.
42:
43: =cut
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Self-documenting code
by stephen (Priest) on Apr 21, 2001 at 11:03 UTC | |
by Starky (Chaplain) on Apr 22, 2001 at 02:05 UTC |