1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/perl -w use strict; use vars qw( @a @b ); open (INFILE, "/idtab.txt") or die $!; my @array = <INFILE>; close (INFILE); my @sorted = map { $_->[0] } sort { $a->[1] <=> $b[1] or $b->[2] <=> $a[2] or $a->[3] <=> $b[3] } map {[$_,(split(/\t/,$_))[2,8,6]] } @array; print @sorted;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
#! /usr/bin/perl use strict; use warnings; my @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] || $a->[3] <=> $b->[3] || $a->[2] <=> $b->[2] } map { [ $_, (split /\s+/, $_)[1,5,7] ] } <DATA>; # Kontrollausgabe use Data::Dumper; print Dumper \@sorted; __DATA__ locus 1 transcript 3/12 confidence 11.000 length 238 locus 2 transcript 3/12 confidence 12.000 length 238 locus 5 transcript 3/12 confidence 15.000 length 238 locus 3 transcript 3/12 confidence 13.000 length 238 locus 6 transcript 3/12 confidence 16.000 length 238 locus 4 transcript 3/12 confidence 14.000 length 238 locus 1 transcript 3/12 confidence 14.000 length 138
map { defined $_ ? $_ : 0 } (split /\s+/, $_)[1,5,7]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#! /usr/bin/perl use strict; use warnings; my @sorted = map { $_->[0] } sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] || $a->[3] <=> $b->[3] } map { [ $_, map { defined $_ ? $_ : 0 } (split /\s+/, $_)[1,5,7] ] } <DATA>; use Data::Dumper; print Dumper \@sorted; __DATA__ locus 1 transcript 3/12 confidence 11.000 length 238 locus 2 transcript 3/12 confidence 12.000 length 238 locus 5 transcript 3/12 confidence 15.000 length 238 locus 3 transcript 3/12 confidence 13.000 length 238 locus 6 transcript 3/12 confidence 16.000 length 238 locus 4 transcript 3/12 confidence 14.000 length locus 1 transcript 3/12 confidence 11.000 length 138
2012-05-03T14:08:00 LinuxerIch würde innerhalb des sort kein or verwenden, sondern || (doppelte Pipe).