http://qs321.pair.com?node_id=355042

Ambidangerous has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, Perl Monks . . . .

Under three different Perls (ActiveState 5.8.3, Cygwin 5.8.2 precompiled, Cygwin 5.8.4 my compile), the following program does two different things, and after playing with it all day, I still can't figure it out.

PURPOSE

This program was automatically generated by a 'cookie cutter' program I wrote called anew.pl. It provides the basic skeleton for any quickie command line utility, using Getopt::Std and Pod::Usage to deliver a default --help and --version command for the new file.

The POD documentation embedded at the end normally is much larger; I've edited it here for space.

MISBEHAVIOR

It runs exactly as expected under AS Perl.

Under either the Cyg prebuilt (or my recent build of 5.8.4 for Cyg), everything works, except --help or -h. Instead of the Pod::Usage you'd expect, you get a blank line.

MY TESTS

I have isolated the problem to something in the HELP_MESSAGE() function. Inserting a print "Here I am!!!" in the sub always works. Something seems to be wonky with Pod::Usage.

I thought this might be some sort of problem with $0 (a tip given in the Pod::Usage docs), but no, when I have it print $0, it's ok, even in the varying invocations

$ perl -w test.pl $ test.pl

Also, when I deliberately hose the Pod::Usage module by specifying a bad input file { -input = "/you/are/hosed.pl" }, it properly complains about it.

Just out of paranoia, I tried it with both DOS and UNIX endlines. No difference.

FINALLY

A search of PM returned an article on coupling these two modules in the way I used, but made no mention of bugs or inconsistent behavior.

Any help would be appreciated.

#!/usr/bin/perl -w test.pl use warnings; use strict; use Getopt::Std; $Getopt::Std::STANDARD_HELP_VERSION = 1; use Pod::Usage; my $VERSION = v1.0.0; my %options; getopts('h', \%options); HELP_MESSAGE() if $options{'h'}; print "ok"; # main program would go here. sub HELP_MESSAGE { # the program reaches this point, I checked. pod2usage ( { -exit_status => 0, -verbose_level => 1 } ); # pod2usage seems to be doing nothing w/Cyg. # Why? } sub VERSION_MESSAGE { return 1 if (lc $ARGV[0] eq "--help"); print "This program is $0, "; printf "version %vd\n", $VERSION; printf "(Using Perl v%vd)", $^V; exit 0; } __END__ =head1 NAME test.pl =head1 SYNOPSIS A one line description, possibly command syntax. [more headers deleted here for conciseness] =head1 OPTIONS =over 4 =item -h, --help Prints synopsis and options, then exits. =item --version Prints version information and exits. =back =head1 ETC [more headers deleted here for conciseness]
Server Error (Error ID 1619167a2051870)

An error has occurred. The site administrators have been notified of the problem and will likely soon fix it. We thank you, for you're patients.

Replies are listed 'Best First'.
Re: Cygwin Pod::Usage malfunction?
by eric256 (Parson) on May 21, 2004 at 05:04 UTC
    Have you tried pod2usage all by itself in a script with just it and a little pod? You might get more help if your question was shorter and got right to this point.

    ___________
    Eric Hodges

      Thanks for the reply, and for the advice. (Sorry, looks like I had my personal --verbose option set.)

      Another data point:

      When you make a special program to test Pod::Usage, outside of the 'cookie cutter program' I showed in my first example, it WORKS.

      The only time Pod::Usage seems to be misfiring is in the original context above.

      #!/usr/bin/perl -w mystery.pl use Pod::Usage; pod2usage ( { -exit_status => 0, -verbose_level => 1 } ); __END__ =head1 SYNOPSIS mystery.pl tests Pod::Usage =head1 OPTIONS Yet this message DOES appear when you summon pod2usage, be it under Cygwin or AS . . . ?!?
Re: Cygwin Pod::Usage malfunction?
by stefan k (Curate) on May 21, 2004 at 14:38 UTC
    Hi,
    the last time I tracked a problem with POD for quite a while it was due to different line endings. My suggestion would be to double- and triple check the \n and \r's in your code.

    Of course I can't promise that this is _it_. Please consider this "just another hint". :-)

    Regards... Stefan
    you begin bashing the string with a +42 regexp of confusion

      SOLVED

      That was the magic bullet. Thanks, Stefan!

      What happened:

      Evidently I have a lazy text editor (however, it has support for DOS/Unix line endings, AND can do Unicode).

      When I took 'test.pl' and saved it as 'test.pl' with Unix line endings, there was no difference. When I took 'test.pl' and saved it as 'testu.pl' with Unix line endings, it worked! Until I changed the name, it didn't feel like it needed to do any work converting line endings.

      That solves the problem. All I have to do is convert over my template files to the correct endings, and I'm good to go.

      Thanks again!