Richard Lee wrote:
I was reading perl magazine and saw
sub readable {
my $number = shift;
$matched = $number =~ s{
(\d+)
(\d{3})
(,|$)
}{$1,$2$3}x;
} while ($matched);
^^^
You have a right brace without a corresponding left brace which is a
syntax error.
You don't need the $matched variable. That is usually written as:
1 while $x =~ s{ (\d+) (\d{3}) (,|$) }{$1,$2$3}x;
Also, see the FAQ for the "official" method:
perldoc -q "How can I output my numbers with commas added"
return $number;
}
on test driven development article by Denis Kosykh.
I am not sure what
(,|$) is doing...
Can someone please explain?
Match either a ',' character or the End-Of-Line and store the result in $3.
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/