in reply to Re: Using -i in oneliner with postprocessing
in thread Using -i in oneliner with postprocessing
(although the weirdly-matched braces scare me a bit)Adding in -MO=Deparse:
The -p option wraps the script in a template equivalent to the following:perl -MO=Deparse -plwe "$h{$_}++ } for (sort {length($a) <=> length($b +) } keys %h) {" BEGIN { $^W = 1; } BEGIN { $/ = "\n"; $\ = "\n"; } LINE: while (defined($_ = <ARGV>)) { chomp $_; ++$h{$_}; } foreach $_ (sort {length $a <=> length $b;} keys %h) { (); } continue { print $_; }
If your code happens to have a closing curly, you can do all kinds of interesting things. My favorite was Abigail-II's substitute for wc, to count lines:while (<>) { your code here } continue { print $_ }
perl -wlpe '}{*_=*.' filename
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Using -i in oneliner with postprocessing
by tkil (Monk) on Apr 28, 2004 at 18:10 UTC | |
by QM (Parson) on Apr 29, 2004 at 17:33 UTC |