in reply to Re^3: High Density Data Aid - swapping specific combination of lines/columns repeatedly
in thread High Density Data Aid - swapping specific combination of lines/columns repeatedly

when we run that in terminal with our text file nothing happens; as in no error messages show up and the text file does not change at all. Can you provide an example of how the script you imagine should look when using it with the text file?
  • Comment on Re^4: High Density Data Aid - swapping specific combination of lines/columns repeatedly

Replies are listed 'Best First'.
Re^5: High Density Data Aid - swapping specific combination of lines/columns repeatedly
by wind (Priest) on Apr 13, 2011 at 19:56 UTC

    Just need to add the opening and closing of the file handles

    use strict; use warnings; my $infile = 'data.txt'; my $outfile = 'newdata.txt'; open my $in_fh, $infile or die $!; open my $out_fh, '>', $outfile or die $!; my %hash; while (<$in_fh>) { chomp; my @data = split /\s+/; push @{$hash{$data[0]}}, @data[3,4]; } for my $key (sort keys %hash) { print $out_fh join(' ', $key, @{$hash{$key}}), "\n"; } close $in_fh; close $out_fh;