Shawn H Corey wrote:
Parag Kalra wrote:
# cat sort.pl
my $column_number = 2; # Sorting by 3rd column since 0-origin based
my $prev = "";
for (
  map { $_->[0] }
  sort { $a->[1] cmp $b->[1] }
  map { [$_, (split)[$column_number]] }

map { [$_, (split)[$column_number]] . " $_" }

  <>
) {
  print unless $_ eq $prev;
  $prev = $_;
}

If you are going to use concatenation then you really don't need to use array references:

for (
  map +(split( "\0", $_, 2 ))[1],
  sort
  map +(split)[$column_number] . "\0$_",
  <>
) {
  print unless $_ eq $prev;
  $prev = $_;
}




John
--
The programmer is fighting against the two most
destructive forces in the universe: entropy and
human stupidity.               -- Damian Conway

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to