I don't know how familiar you are with perlstyle, but I would have thought
you would be quite familiar. It seems somewhat hypocritical to include
comments such as:

"Similarly, just because an operator lets you assume default arguments
doesn't mean that you have to make use of the defaults. The defaults are
there for lazy systems programmers writing one-shot programs. If you want
your program to be readable, consider supplying the argument."

and then do the opposite in the FAQs. The other part that strikes me is:

"For instance ** open(FOO,$foo) || die "Can't open $foo: $!"; ** is better
than ** die "Can't open $foo: $!" unless open(FOO,$foo); **  because the
second way hides the main point of the statement in a modifier."

As to how I would rewrite the code? My Perl, as I mentioned, is somewhat
shit, but I would suggest something along the lines of:

sub commify {
    my $number = $_[0]; # Grab the first argument passed
    while ($number =~ s/^([-+]?\d+)(\d{3})/$1,$2/) {;}
    return $number;
}

Perhaps it's not very 31337, but it gets its job done, and should be
understandable - we'd hate to breed more blind cargo-cult-coders, wouldn't
we?

+Pete


----- Original Message -----
From: "Nathan Torkington" <[EMAIL PROTECTED]>
To: "Pete Sergeant" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Friday, September 21, 2001 9:48 PM
Subject: Re: FAQ Ideas


> Pete Sergeant writes:
> >
http://www.perldoc.com/perl5.6.1/pod/perlfaq5.html#How-can-I-output-my-numbe
> > rs-with-commas-added-
> >
> > Sucks. The code there is not easily understandable to most people I
would
> > imagine are reading it. Perhaps someone would like to rewrite the
examples
> > to be somewhat more understandable and better programming practice.
>
> The FAQ presents solutions to problems, not tutorials in how to
> program.  I have no idea what you mean about incomprehensible code.
> How would you rewrite this to reflect "better programming practice"?
>
>     sub commify {
>         local $_  = shift;
>         1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
>         return $_;
>     }
>
> Thanks,
>
> Nat
>

Reply via email to