On Sat, 16 Mar 2002 19:17:25 +0200, [EMAIL PROTECTED] (Bruce Ambraal) wrote:
>I am want to add digits in In_digits together. >Print total to screen. >Could someone help? >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); Don't you know the people around here take the weekends off? Things get answered faster on weekdays. If you want to print to screen, you don't need OUTPUT, that is automatically handled by STDOUT. #!/usr/bin/perl -w open(INPUT, "In_digits") || die; $tot =0; while (<INPUT>) { if (/(\d{1})(\,)(\d{3})/) { $_ =~ s/,//; $tot += $_; } else { print "warning: line of unexpected format ($_)\n"; } } print "total = $tot\n"; close(INPUT); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]