blackdragoen has asked for the wisdom of the Perl Monks concerning the following question:
and need the sorted one as below05,sometext5 02,sometext2 10,sometext10 03,sometext3
i used tell and seek function to swap this. But one of my main aim is performance ,because its going to handle a large files about 500 Mb to 1Gb I wrote the below code. It works fine but takes time for large files. Any suggestions please Regards, blackdragoen02,sometext2 03,sometext3 05,sometext5 10,sometext10
open(IN,"in.txt"); while(<IN>) { if($_=~m/^\n/) { $tell_val=tell(); } if($_=~m/^\d+/) { $has{$&}=$tell_val if($tell_val ne ''); } } open(OUT,">output.txt"); foreach(sort{$a<=>$b}(keys %has)) { seek(IN,$has{$_},0); $line=<IN>; print OUT $line; print $_; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Sort lines in a file
by lidden (Curate) on Feb 14, 2008 at 14:03 UTC | |
|
Re: Sort lines in a file
by Erez (Priest) on Feb 14, 2008 at 14:18 UTC | |
by toolic (Bishop) on Feb 14, 2008 at 15:47 UTC | |
by MidLifeXis (Monsignor) on Feb 14, 2008 at 16:37 UTC | |
by blackdragoen (Novice) on Feb 15, 2008 at 04:33 UTC |