in reply to Re^5: 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 = -0.0001; # Zeroize numbers smaller than this my $NO_DATA = -9999; 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>){ next if $. < 7; # Skip first 6 lines chomp $_; my @values = split; for (@values){ if($_ == $NO_DATA){ # leave -9999 alone } elsif( $_ < $minimum ){ $_ = 0; # or $NO_DATA; # replace small negative with 0 or -999 +9 } else { $_ *= $constant; # multiply other numbers by constant } } print $out join ( " ",@values),"\n"; } close $out; close $in;

        "You're only given one little spark of madness. You mustn't lose it."         - Robin Williams