in reply to Re^4: Multiply the numbers in a text file
in thread Multiply the numbers in a text file

After trying out your code, I get the output which I'm unable to interpret

OB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)GLOB(0xc828e8)

It looks something like this

It doesn't write in the output file except for the first six lines. Can you tell me what the error is?

Replies are listed 'Best First'.
Re^6: Multiply the numbers in a text file
by NetWallah (Canon) on May 10, 2015 at 16:32 UTC
    #!/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

Re^6: Multiply the numbers in a text file
by aaron_baugher (Curate) on May 10, 2015 at 16:25 UTC

    The code I showed was not complete; it was just portions to demonstrate how to do the number changes. It's customary to show your code that you need help with, so we can point out what's causing the errors.

    Aaron B.
    Available for small or large Perl jobs and *nix system administration; see my home node.