and then moved the infile.tmp to infile. My task was accomplished, but I couldn't help but wonder if it could have been easily accomplished with inplace editing. I hadn't tried at first, because I thought the print would no longer go to the correct output file once the input file was completely read; a quick try confirmed this: when the implicit readline is returning undef, it also closes ARGVOUT and re-selects STDOUT. After a few seconds, the solution became obvious:perl -plwe'$h{$_}++ } for (sort { length($a)<=>length($b) } keys %h) { +' infile >infile.tmp
perl -i.bak -plwe'$h{$_}++; last if eof } for (sort { length($a)<=>len +gth($b) } keys %h) {' infile
|
---|
Replies are listed 'Best First'. | |
---|---|
•Re: Using -i in oneliner with postprocessing
by merlyn (Sage) on Apr 28, 2004 at 14:39 UTC | |
Re: Using -i in oneliner with postprocessing
by tkil (Monk) on Apr 28, 2004 at 08:29 UTC | |
Re: Using -i in oneliner with postprocessing
by tkil (Monk) on Apr 28, 2004 at 07:50 UTC | |
by QM (Parson) on Apr 28, 2004 at 14:56 UTC | |
by tkil (Monk) on Apr 28, 2004 at 18:10 UTC | |
by QM (Parson) on Apr 29, 2004 at 17:33 UTC | |
Re: Using -i in oneliner with postprocessing
by Roy Johnson (Monsignor) on Apr 28, 2004 at 15:01 UTC | |
by merlyn (Sage) on Apr 28, 2004 at 15:44 UTC |