I'll pretend I did not see
### POD ###
I'd like to introduce you to
=pod
I trust you'll make the change accordingly.
Seeing as you're on the right track ( pod ),
but are still have a little trouble( sub usage ... <<END; ??? nooo ), i'd like to introduce you to a new friend, Pod::Usage. It'll make the redundant sub usage go away.
I hope you'll embrace it, and to help you do so, here's a gem from ybic The Dynamic Duo --or-- Holy Getopt::Long, Pod::UsageMan!
Ooops, I almost forgot, ;D
____________________________________________________ ** The Third rule of perl club is a statement of fact: pod is sexy. | [reply] [d/l] [select] |
Ok, I'm trying to fix up the Pod as you suggested. But I'm not sure how to get the same functionality as my &usage hack.
The script is designed to be symlinked:
(my $script_name = $0) =~ s#.*/##; # $0 = full path to script
my $file = $ARGV[0] || &usage($script_name);
And the usage message is related to the name of the script.
Is there anyway to do this with Pod::Usage? Is the symlink design of this utility bad? | [reply] [d/l] |
It didn't catch my eye the first time, but don't trust $0.
It's a bad shell scripting habit.
use __FILE__ instead. Sure you can't embed it in string unless you use "@{[__FILE__]}" but it's just the same, it can't be changed, while $0 can.
Now, Pod::Usage's pod2usage function does look at $0 if you don't pass the -input option, but that's cause __FILE__ is local to each file, and it wouldn't work otherwise, and you can always say pod2usage( -input => __FILE__ );.
If you symlink a file as 'FOO', __FILE__ will contain that value, although i'm not sure how portable that is (i'm willing to venture a guess that it is).
Now to your new question, yes, the symlink design of the utility is bad IMHO.
Either create 2 separate scripts, or just make each Sub an option (with Getopt)
And while i'm at it, you shouldn't exit
from a subroutine. Subs should return. You shouldn't generally use exit to terminate your program normally.
update: oh, btw, each pod token should be surrounded by lone newlines, as in perl -e " print qq{die;\n\n=pod\n\nhi there\n\n=cut\n\n}; "
____________________________________________________ ** The Third rule of perl club is a statement of fact: pod is sexy.
| [reply] [d/l] [select] |