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

Adding the input file digits together (Come on guys)

Thread Next
From:
Bruce Ambraal
Date:
March 17, 2002 22:41
Subject:
Adding the input file digits together (Come on guys)
Message ID:
sc939a4b.088@cct.org.za
Hi 
I am want to add digits in In_digits together.
Print total to screen.
Could someone help?

Thanx

Bruce


In_digits:
1,200
2,400

#!/usr/bin/perl -w
open(INPUT, "In_digits") || die;
open(OUTPUT, ">Out_digits") || die;
while (<INPUT>) {
       if (/(\d{1})(\,)(\d{3})/) {     
                print OUTPUT;
        } else {
                print "warning: line of unexpected format ($_)\n";
        }
print
}
close(INPUT);
close(OUTPUT);




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