in reply to Re: Storable 2 Text - An editor for data files created by Storable.pm
in thread Storable 2 Text - An editor for data files created by Storable.pm

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?
  • Comment on Re: Re: Storable 2 Text - An editor for data files created by Storable.pm
  • Download Code

Replies are listed 'Best First'.
Re: Re: Re: Storable 2 Text - An editor for data files created by Storable.pm
by PodMaster (Abbot) on Aug 16, 2002 at 21:59 UTC
    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.