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: Intermediate: Re: [yasdel] Check if txt file contains numbers: Edit Log



BillKSmith
Veteran

Sep 19, 2010, 2:41 PM


Views: 1264
Re: [yasdel] Check if txt file contains numbers

I recommend using the function 'is_numeric' in the CPAN module Data::Validate to select the numbers for processing.



Code
 use strict;   
use warnings;
use Data::Validate qw(:math);
foreach my $line (<DATA>) {
chomp ($line);
my @nums = split ' ', $line;
foreach my $num (@nums) {
$num *= 1.5 if is_numeric($num);
}
print "@nums\n";
}
__END__
0 700000 HR 700000 1300000 H3 1300000 2100000 H2 2100000 3800000 HH 3800000 4500000
HQ 4500000 5000000 HP 5000000 5700000 HO



Edit: Simplified processing.
Good Luck,
Bill

(This post was edited by BillKSmith on Sep 20, 2010, 5:57 AM)


Edit Log:
Post edited by BillKSmith (Veteran) on Sep 20, 2010, 3:18 AM
Post edited by BillKSmith (Veteran) on Sep 20, 2010, 5:57 AM


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

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