Hi List,<div><br></div><div>I had a scenario recently where 'pod2usage' was failing (ref: Pod::Usage) when used in conjunction with a GetOptions call -> the code went something like this:</div><div><br></div><div>

<div>  my $man = 0;</div><div>  my $help = 0;</div><div>  my $cmd = "";</div><div>  GetOptions(</div><div>    'help|h|?' => \$help,</div><div>     man => \$man,</div><div>     "cmd=s" => \$cmd,</div>

<div>  ) or pod2usage(2);</div><div>  pod2usage(0) if $help;</div><div>  pod2usage(-exitstatus => 0, -verbose => 2) if $man;</div><div>  pod2usage(2) unless $cmd;</div><div><br></div></div><div>Now call "<a href="http://blah.pl">blah.pl</a>  --help" and I get an error on the ...if $help line number.</div>

<div><br></div><div>So drilling into it further, I identify that the problem is related to how I am manipulating $0 to also show automatically my command line arguments, and how Pod::Usage attempts to read from $0.  Thus depending on the order in which you call pod2usage vs manipulate $0, you may or may not get an error.</div>

<div><br></div><div>Some further reading of the perlvar doc says that manipulating $0 to status information, is a normal thing....  Looking at FindBin, etc al also shows that $0 is consulted (at call-time) for its current value.</div>

<div><br></div><div><br></div><div>I have posted previously some discussion on the use of $0 (eg: pidof <a href="http://somescript.pl">somescript.pl</a> vs killall <a href="http://somescript.pl">somescript.pl</a>) -> where that discussion depended on your point of view.</div>

<div><br></div><div><br></div><div>However, this one seems somewhat contradictory -> to my eyes, either $0 should contain a somewhat non-updatable pointer to the location of the script, *or* you can update its value to show the current script-status, but then cause your tools to break.  Obviously there are workarounds, such as monkey patching FindBin, pos2usage, etc, but that gets somewhat cumbersome.  And I dont recall there being a separate variable (other than $0), which holds the path to the executing script.</div>

<div><br></div><div><br></div><div>So how do I update $0 to show script status, but also to have pod2usage, FindBin, etc do the right thing?</div><div>I dont expect an easy answer to this... other than:</div><div>a) wont fix</div>

<div>b) use some variation of another variable ** to fix either the CPAN modules, or script status.</div><br class="Apple-interchange-newline"><div><br></div><div>** I vote $^0... I dont think it is being used, and it follows both the $0 = name and $^ = internal-var convention.</div>

<div><br></div><div>Thoughts?</div><div>Mathew</div>