On Nov 9, Robert Thompson said:
>I felt it would have been too obligatory if I had opened the e-mail
>"Dear Mr. Pinyan," :)
Heehee. :)
Honestly, though, I'm only this good so that other people can be good. It
does the Perl community no good to have a handful of illuminati -- if they
become inaccessible, what are people going to do?
> "?" if
> "!" not
> "=" equal
>insted of:
> "?" if
> "!" not equal
Happens to me every now and then too -- that's why I caught it. I make a
similar mistake with the look-behind extensions:
(?<= ... )
(?<! ... )
I often write (?<!=...) or something like that. It takes some getting
used to.
Think of the '!' and '=' as being the FIRST character of != or ==, and it
might stick a little better.
>my $num = reverse $ARGV[0];
>if ($num =~ /\./) {
> unless ($num =~ /^[0-9]{2}\./) {
> print "Error\n"; exit(1);
> }
>}
>$num =~ s/([0-9]{3}) (?=\d) (?!\d*\.)/$1,/xg;
That looks fine to me... You could use \d instead of [0-9], though. Here
is how I might write the code:
my $num = reverse $ARGV[0];
die "Number must have two decimal places if any.\n"
if $num =~ /^(\d+)\./ and length($1) != 2;
$num =~ s/(\d{3})(?=\d(?!\d*\.))/$1,/g;
$num = reverse $num;
I changed the regex a bit, but the meaning is the same.
--
Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/
RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]