[Mastering-perl] Check out the chapters on configuration, subroutines, and Pod

Florian Merges fmerges at cpan.org
Sun Sep 17 06:17:46 EDT 2006


Hi

2006/9/17, Philippe Bruhat (BooK) <philippe.bruhat at free.fr>:
>
> Le vendredi 15 septembre 2006 à 18:04, brian d foy écrivait:
> > I've been quiet about _Mastering Perl_ for a while: it took me a bit
> > ot get over the conference season and get back to some serious work.
> >
> > This week I've been working on finishing off the configuration chapter:
> >
> >
> http://www252.pair.com/comdog/mastering_perl/Chapters/configuration.html
>
> Attached you'll find a patch resulting from my re-reading this chapter.
>
> I put the value for e, and rounded Phi and e (so I've written them 2.72
> and 1.62).
>
> Also, I think you are wrong when describing Getopt::Long... You write:
>
>     The M<Getopt::Long> module doesn't handle the single character
>     switches, and all of its switches start with a double hyphen. I give
>     its C<GetOptions> function a list of key-value pairs. The key give the
>     switch name and the value is a reference to a variable where
>     C<GetOptions> will put the value.


I also agree that this is wrong, its primary use or intended use is to
support the POSIX long names options, but it automatically accept also the
short version, and even mixing long with shorts...


        #!/usr/bin/perl
>
>         use Getopt::Long;
>
>         my $result = GetOptions(
>             debug   => \ my $debug,
>             verbose => \ my $verbose,
>             );
>
>         print <<"HERE";
>         The value of
>             debug       $debug
>             verbose     $verbose
>         HERE
>
> But when I save this code as getopt_long and run it with various
> command-line
> parameters, I see that it actually accepts single character switches,
> even abbreviations and that the double hyphen is not required:
>
>     $ getopt_long -debug
>     The value of
>         debug       1
>         verbose
>     $ getopt_long -v
>     The value of
>         debug
>         verbose     1



You must take care in situations like 'version' and 'verbose', when using
short names. For this I allways write it with the different options, mean
'verbose|v' 'version|V' and so on, because otherwise you'll get an error
message on the last version, but I think to remember that with older version
he silently applied the option to one of the options.

#!/usr/bin/perl

use Getopt::Long;

my $result = GetOptions(
    'debug'   => \ my $debug,
    'verbose|v' => \ my $verbose,
    'version|V' => \ my $version,
);

print <<"HERE";
The value of
debug       $debug
verbose     $verbose
version     $version
HERE


perl t.pl -d --v -verbose
The value of
debug       1
verbose     1
version     1


Regards,

Florian

--
> Philippe "BooK" Bruhat
>
> Mankind is the story of the same mistakes in different places.
>                                                  (Moral from Groo #1
> (Image))
>
>
> _______________________________________________
> Mastering-perl mailing list
> Mastering-perl at theperlreview.com
> http://five.pairlist.net/mailman/listinfo/mastering-perl
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://five.pairlist.net/pipermail/mastering-perl/attachments/20060917/1f43c6a8/attachment.html


More information about the Mastering-perl mailing list