# The following was supposedly scribed by
# Johan Vromans
# on Friday 25 June 2004 03:00 am:

>This will have a nasty side effect, as shown below:
>
>  $ round --round=42 --help
>  usage:  round <filename>
>  options:  --round <float>   (default  42)

Yes, this is correct.  But I was planning something more along these lines:

use Getopt::Long;
my $all = 7;
my $foo = "bar";

my @opt_build = (
        ['a|all=i', \$all, "value for all (default $all)"],
        ['f|foo=s', \$foo, "string for foo (default $foo)"],
        ['h|help' , sub { usage()}, "show this help message"],
        );
my %opts = map({$_->[0] => $_->[1]} @opt_build);
my @help = map({"$_->[0]  $_->[2]"} @opt_build);
GetOptions(%opts);

sub usage {
        my $caller = $0;
        $caller =~ s#.*/##;
        die join("\n", "usage:", "  $caller <file>", @help), "\n";
}
END

And, in my mythical modified version of perldoc, I'd need to run up to the 
point where @help is declared, then exit.

Maybe instead of 'my @help=', we do 'Pod::Dynamic->usage(map({"$_->[0]  
$_->[2]"} @opt_build));' and that triggers an exit from the 'do()' (for 
instance when ($0 =~ m/perldoc/)), and declares main::usage() otherwise.

Something along those lines anyway.

--Eric
-- 
Peer's Law: The solution to the problem changes the problem.

Reply via email to