In my instance, the 0+ solution would not produce the results I desire. For example, 
imagine the input string is "0000000.00" as in
a dollar amount. The result I desire is "0.00", while the 0+ method results in "0". 
The regex that Joe provided produced my desired
result, while the 0+ maybe useful for other things.

Dirk Bremer - Systems Programmer II - ESS/AMS  - NISC St. Peters
636-922-9158 ext. 652 fax 636-447-4471

[EMAIL PROTECTED]
www.nisc.cc

----- Original Message -----
From: <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, February 12, 2002 11:36
Subject: RE: Zero-suppression Regex


> As Michael G Schwern over on the Fun With Perl group said:
> > Folks, I'm clawing my eyes out here.  Stop hitting the regex crack
> pipe!
>
> Although he was specifically talking about printf vs a regex for zero
> padding numbers, the principle still applies. Perl has an incredibly
> efficient "convert number-like text into a proper number" function. It works
> implicitly every time you use a numerical operator on a scalar. The regex
> tool is comparatively slow and an all-purpose, robust solution is
> non-trivial.
>
> Why not just use 0+$_ and let perl work its magic. I challenge any of you
> regex "pushers" out there to write a regex that beats this in either speed
> or elegance.
>
> BTW Joe's solution s/^-?0+(?=\d)// will fail for negative numbers. I would
> post a fix but I appear to be on my high horse at the moment :-)


_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to