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

By move to the right, I take it you mean append each new measurement to the appropriate sample's list.

Given that each row contains the sample's name, we don't need to keep track of the fact that there are exactly 142 samples. Instead, this just adds each subsequent measurement to that sample's array of values. And at the end we write out all the results associated with each sample.

  • Comment on Re^3: High Density Data Aid - swapping specific combination of lines/columns repeatedly

Replies are listed 'Best First'.
Re^4: High Density Data Aid - swapping specific combination of lines/columns repeatedly
by Renyulb28 (Novice) on Apr 13, 2011 at 19:06 UTC
    so should the
    @data[3,4]
    be
    @data[4,5]
    instead since the observations are columns 4 and 5?

      No, I don't think that's what you want

      Array indexes in perl start from 0, ie column 1 is $data[0].

      Therefore columns 4 and 5 are represented by @data[3,4] in an array.

Re^4: High Density Data Aid - swapping specific combination of lines/columns repeatedly
by Renyulb28 (Novice) on Apr 13, 2011 at 19:45 UTC
    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?

      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;