in reply to manipulating a data table

No need for Perl, you can use a simple bash script:
#!/bin/bash file=$1 paste <(join -1 1 -2 2 -o 1.1 2.1 "$file" \ <(cut -f1,2 "$file" | sort -k2nr | nl | sort -k2) ) \ <( cut -f1,3 "$file" | sort -k2nr | nl | sort -k2 | cut -f +1)

But jokes aside:

#!/usr/bin/perl use warnings; use strict; use feature qw{ say }; # Read the input. my @input; while (<>) { push @input, [ split ]; } # Sort by columns, save the line number. my @output = map [ $_->[0] ], @input; for my $c (1, 2) { my $x = 1; $output[$_][$c] = $x++ for sort { $input[$b][$c] <=> $input[$a][$c +] } 0 .. $#input; } # Print the line numbers using the original order. for my $l (0 .. $#input) { say join "\t", @{ $output[$l] }; }
($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^2: manipulating a data table
by perldigious (Priest) on Aug 16, 2016 at 17:24 UTC

    I admit you got me good with this one choroba.

    I started at anger and prepared to load up my rarely used down vote gun, then went on to irritation when I saw I was out of ammunition, then went on to a sinking feeling in my stomach when I checked who the offending monk was, then to confusion as I checked to make sure it wasn't somehow April 1st again already, and then returned to a state of relaxation with an audible laugh when I actually finished reading past the opening line.

    Well played sir, well played...

    I love it when things get difficult; after all, difficult pays the mortgage. - Dr. Keith Whites
    I hate it when things get difficult, so I'll just sell my house and rent cheap instead. - perldigious
Re^2: manipulating a data table
by v15 (Sexton) on Aug 16, 2016 at 19:30 UTC
    Hi, The perl code worked really well and for the columns more than 2 i can just use
    for my $c(1..16)
    Can you explain me a little bit what some portions of your code is doing. In the while loop you are adding each line of the input file as an array ref into an array named input
    while (<>) { chomp; my @s = split /\t/,$_; push @input ,\@s; }
    Can you explain me the use of map and what exactly is that line doing? Also can you right this statement in the loop form rather than one line. It is easy to understand
    $output[$_][$c] = $x++ for sort { $input[$b][$c] <=> $input[$a][$c] } +0 .. $#input;
    Thanks
      To see what structure the first loop creates, use
      use Data::Dumper; print Dumper(\@input);

      You'll get the following output:

      The map line

      my @output = map [ $_->[0] ], @input;

      creates the output, it maps each element of @input to a reference to a new array containing its first element, i.e.

      The last cited line sorts the array indices (that represent input line numbers) by $c-th element (reversed), and than sets $c-th element of the output to be the order number. Thus, the first iteration processes the second column:

      and the second one the next one:

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,