in reply to Re: Multiply the numbers in a text file
in thread Multiply the numbers in a text file
#!/usr/bin/perl use strict; use warnings; my $input = 'input.txt'; my $output = 'output.txt'; my $constant = 15; #number you are multiplying by my $minimum = 20; # Smallest number to multiply my $zero_replace = 666; # Replacement for zero open my $in, "<", $input or die "Could not open $input for reading:$!" +; open my $out, ">>", $output or die "Could not open $output for append: +$!"; while (<$in>){ chomp $_; $_ = $zero_replace if 0 == $_; # next if $_ < $minimum; print $out ($_ * $constant),"\n"; } close $in; close $out;
"You're only given one little spark of madness. You mustn't lose it." - Robin Williams
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Multiply the numbers in a text file
by zegoofer (Initiate) on May 10, 2015 at 01:40 UTC | |
by wrog (Friar) on May 10, 2015 at 05:40 UTC |