
KevinR
Veteran

Apr 20, 2009, 11:21 PM
Views: 2185
|
|
Re: [dsatish] Regular expressions needed..
|
|
|
It would be nice to see some effort on your part first to try and solve your requirements, even if it does not work.
$num = 12.89383787; if ($num =~ /(\d\d\.\d\d)/) { $num = $1; } else { $num = substr $num,0,2; } print $num; Same thing using the ternary operator:
$num = 1289383787; $num = $num =~ /(\d\d\.\d\d)/ ? $1 : substr $num,0,2; print $num; -------------------------------------------------
(This post was edited by KevinR on Apr 20, 2009, 11:23 PM)
|