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 explaining it line by line in lucid language, I would be grateful to him... It will help me in understanding the algorithm... Cheers, Parag On Sat, Oct 31, 2009 at 2:08 AM, John W. Krahn <jwkr...@shaw.ca> wrote: > 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/ > > >