Re: Emulating Sort through Perl

2009-10-30 Thread Parag Kalra
Hi Randal, I apologise for not crediting Perl Monks forum here. I won't repeat this henceforth :) So for all those who are not aware of what is going on. You can have a look at here - http://www.perlmonks.org/?node_id=803894 It also contains a small story about what how I first came in acquainta

Re: Emulating Sort through Perl

2009-10-30 Thread Randal L. Schwartz
> "Parag" == Parag Kalra writes: Parag> I am trying to emulate Linux 'sort' command through Perl. I got Parag> following code through Internet to sort the text file: "Through the internet"... like somehow the internet magically created your code? You could at least credit your perlmonks exc

Re: Emulating Sort through Perl

2009-10-30 Thread Jim Gibson
On 10/30/09 Fri Oct 30, 2009 1:50 PM, "Parag Kalra" scribbled: > Folks, > > Thanks a bunch for your replies... > > Honestly speaking I couldn't understand the code completely as its not mine > and being a beginer my head is spinning between these references and > complexly & strangely used so

Re: Emulating Sort through Perl

2009-10-30 Thread Parag Kalra
Folks, Thanks a bunch for your replies... Honestly speaking I couldn't understand the code completely as its not mine and being a beginer my head is spinning between these references and complexly & strangely used sort, map operators So if anyone of you can walk me through the above lines ex

Re: Emulating Sort through Perl

2009-10-30 Thread John W. Krahn
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]] . " $_" } <> ) { pri

Re: Emulating Sort through Perl

2009-10-30 Thread Parag Kalra
Thanks to all of you for sharing your codes & notes... 'sort { $a->[1] cmp $b->[1] || $a->[0] cmp $b->[0] }' - It did the trick...Thanks once again... Cheers, Parag On Sat, Oct 31, 2009 at 1:29 AM, John W. Krahn wrote: > Parag Kalra wrote: > >> Hello Folks, >> > > Hello, > > > This is my f

Re: Emulating Sort through Perl

2009-10-30 Thread Philip Potter
2009/10/30 Jim Gibson : > Approach 1. is called a "stable sort". As you can see, Perl's sort gives you > a stable sort, as the last two lines are in the order they appear in the > original file. The Unix sort is not stable, so the lines with equal keys get > reversed in the output. Whether or not y

Re: Emulating Sort through Perl

2009-10-30 Thread Jim Gibson
On 10/30/09 Fri Oct 30, 2009 12:37 PM, "Parag Kalra" scribbled: > Hello Folks, > > This is my first post here. > > I am trying to emulate Linux 'sort' command through Perl. I got following > code through Internet to sort the text file: > > # cat sort.pl > my $column_number = 2; # Sorting by

Re: Emulating Sort through Perl

2009-10-30 Thread Shawn H Corey
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 unl

Re: Emulating Sort through Perl

2009-10-30 Thread John W. Krahn
Parag Kalra wrote: Hello Folks, Hello, This is my first post here. I am trying to emulate Linux 'sort' command through Perl. I got following code through Internet to sort the text file: # cat sort.pl my $column_number = 2; # Sorting by 3rd column since 0-origin based my $prev = ""; for (

Emulating Sort through Perl

2009-10-30 Thread Parag Kalra
Hello Folks, This is my first post here. I am trying to emulate Linux 'sort' command through Perl. I got following code through Internet to sort the text file: # cat sort.pl my $column_number = 2; # Sorting by 3rd column since 0-origin based my $prev = ""; for ( map { $_->[0] } sort { $a->[1