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

with that method, how can I specific my parameters of lines that I wish to move to the right of the previous set of 142 samples from columns 4 and 5?
  • Comment on Re^2: High Density Data Aid - swapping specific combination of lines/columns repeatedly

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

    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.

      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.

      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;