ioana has asked for the wisdom of the Perl Monks concerning the following question:
The print map command will only print out the sorted column#!/usr/bin/perl my @rows = (); open FH, "LINE" or die $!; open FHO, ">SORT"; while (<FH>) { chomp; push @rows, [ split /\|/ ]; #I guess this should work with any separators,e.g \t as well? } close FH; #my @sorted = sort { $a->[2] <=> $b->[2] } @rows; #printf "%g\t%g\t%i\t%g\n", sort { $a->[2] <=> $b->[2] } @rows; #foreach ( sort {$a->[2] <=> $b->[2] } @rows ) { #printf "$_ \n" } print map {$_->[2] . "\n" } sort { $a->[2] <=> $b->[2]} @rows; #print map {$_ . "\n" } sort { $a->[2] <=> $b->[2]} @rows; exit
but it printed out the columns on top of each other. I would appreciate your help. I want especially to understandfor($i = 0; $i <4; $i++) { print map {$_->[$i] . "\n" } sort { $a->[2] <=> $b->[2]} @rows;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: how to print sorted data
by Enlil (Parson) on Jul 15, 2003 at 20:46 UTC | |
|
Re: how to print sorted data
by Zed_Lopez (Chaplain) on Jul 15, 2003 at 20:45 UTC | |
|
Re: how to print sorted data
by sgifford (Prior) on Jul 15, 2003 at 20:17 UTC |