CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [dsatish] Regular expressions needed..: Edit Log



KevinR
Veteran


Apr 20, 2009, 11:21 PM


Views: 4498
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.


Code
$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:


Code
$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)


Edit Log:
Post edited by KevinR (Veteran) on Apr 20, 2009, 11:23 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives