write a perl script to print the sum of all numbers present in the file.
#!/usr/bin/perl
open(FH, "/home/ataul/practice/numbers.txt") or die "couldn't open a file, $!";
$sum = 0;
while($lines = <FH>)
{
$sum += $lines;
}
print "$sum\n";
numbers.txt file content:
12
26
95
-85
42
15
94
23
75
49
and the output for the above script is:
346
#!/usr/bin/perl
open(FH, "/home/ataul/practice/numbers.txt") or die "couldn't open a file, $!";
$sum = 0;
while($lines = <FH>)
{
$sum += $lines;
}
print "$sum\n";
numbers.txt file content:
12
26
95
-85
42
15
94
23
75
49
and the output for the above script is:
346
No comments:
Post a Comment