[Omaha.pm] Substitution loop
Andy Lester
andy at petdance.com
Tue Jul 31 12:38:02 PDT 2007
On Jul 31, 2007, at 2:17 PM, Jay Hannah wrote:
> Substitution loop at CommonShare.pm line 65.
>
> line 65 looks harmless enough:
>
> $d1=~s/[^\d]//g;
>
> Anyone seen that error before?
>
> Diving.... :)
Sure. The /g is a modifier saying "do this on everything throughout
the string". In this case, it's removing every non-digit character
from the string.
It would be even better to have it as
$dl =~ s/[^\d]+//g;
That way if you have a string of ten non-digits, they'll all get
removed at once, rather via ten checks.
You can also use the tr/// operator for this sort of thing, if you want.
xoxo,
Andy
--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance
More information about the Omaha-pm
mailing list