develooper Front page | perl.beginners | Postings from December 2002

substitution or matching regex

Thread Next
From:
David O'Dell
Date:
December 31, 2002 10:16
Subject:
substitution or matching regex
Message ID:
003101c2b0f8$bd1a7180$a23ea8c0@ad.ofoto.com
I have a variable:
$NUM = '14.45905495';
and I want to remove the trailing digits and only leave 2 after the period
so it ends up

'14.45'

I've tried to do this but it appears to return as an array and always prints
out "1".

#!perl -w

$NUM = '14.45905495';
@POST = ($NUM =~ /\d\.\d{2}/);
print "new value is $POST[0]\n";

after being run


$ ./test_ex.pl
new value is 1




Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About