Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Summing numbers in a file

by hippo (Bishop)
on Jun 03, 2020 at 12:27 UTC ( [id://11117641]=note: print w/replies, xml ) Need Help??


in reply to Summing numbers in a file

Building on everyone else's comments and leveraging Math::Calc::Parser, here is a simple yet reasonably secure solution.

#!/usr/bin/env perl use strict; use warnings; use autodie; use feature 'say'; use Math::Calc::Parser 'calc'; open my $in, '<', 'numbers.txt'; open my $out, '>', 'sum.txt'; while (<$in>) { say $out calc $_; } close $out; close $in;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11117641]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-23 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found