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

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;
  • Comment on Re^5: High Density Data Aid - swapping specific combination of lines/columns repeatedly
  • Download Code