[Mastering-perl] Check out the chapters on configuration,
subroutines, and Pod
Philippe Bruhat BooK
philippe.bruhat at free.fr
Sun Sep 17 05:17:49 EDT 2006
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.
#!/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
--
Philippe "BooK" Bruhat
Mankind is the story of the same mistakes in different places.
(Moral from Groo #1 (Image))
-------------- next part --------------
Index: configuration.pod
===================================================================
--- configuration.pod (révision 93)
+++ configuration.pod (copie de travail)
@@ -49,7 +49,7 @@
still look at the code (we do like open source, after all), but they
don't need to.
-Now that I've said all that, sometimes har-coded really isn't all that
+Now that I've said all that, sometimes hard-coded really isn't all that
bad, although I wouldn't really call this next method "configuration".
When I want to give a datum a name that I can reuse, I pull out the
C<constant> pragma, which creates a subroutine that simply returns the
@@ -79,7 +79,7 @@
sub SECS_PER_YEAR { $secs_per_year }
}
-Curiously, these two number almost the same, give or take ten million.
+Curiously, these two numbers are almost the same, give or take ten million.
The seconds per year (ignoring partial days) is 3.16e7, which is
pretty close to C<Pi> times ten million.
@@ -94,7 +94,7 @@
ReadOnly::Array my @Fibonacci => qw(1 1 2 3 5 8 13 21 );
- ReadOnly::Hash my %Natural => ( e => , Pi => 3.14, Phi => 1.61 );
+ ReadOnly::Hash my %Natural => ( e => 2.72 , Pi => 3.14, Phi => 1.62 );
With Perl 5.8 or later, I can leave off the second level package name
and let Perl figure it out based on the variable type that I give it.
@@ -106,7 +106,7 @@
ReadOnly my @Fibonacci => qw(1 1 2 3 5 8 13 21 );
- ReadOnly my %Natural => ( e => , Pi => 3.14, Phi => 1.61 );
+ ReadOnly my %Natural => ( e => 2.72, Pi => 3.14, Phi => 1.62 );
=head2 Code in a separate file
@@ -323,7 +323,7 @@
the way the program behaves (although in the odd case they do nothing
but add compatibility for foreign interfaces). In T<Advanced Perl
Programming>, Simon Cozens talked about the different things that Perl
-programmers consistently re-invent (which is different that
+programmers consistently re-invent (which is different from
re-inventing consistently). Command line switches is one of them, and
indeed, when I look on CPAN to see just how many there are, including
M<Getopt::Std>, M<Getopt::Long>, and 87 other modules with M<Getopt>
@@ -913,7 +913,7 @@
probably if I can send output to the terminal or get input
from it.
-I can check C<STDout> to see if the output will go to a terminal.
+I can check C<STDOUT> to see if the output will go to a terminal.
Using the C<-t> file test tells me if the filehandle is connected to a
terminal. Normally, command line invocations are so connected.
More information about the Mastering-perl
mailing list