No such thing as a small change | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
I put this on my scratchpad about a month back: Cool vi macro: @p runs Perl code between #! and __END__ lines on any text after the __END__, preserving the perl code. The "let" command to set @p only works in vim, but the macro (drop the quotes and replace \r with ^V^M -- probably by typing ^V^V^V^M) works in any reasonable vi-alike.
L goes to the bottom of the current screen so that the next bit is unlikely to fail (which would halt the macro); ?^#! searches for the first line of the 'script'; /^__END__ searches for the end of what needs to be pasted because it won't be output when perl is run; y'' yanks from the __END__ through the #! line; '' jumps back to the __END__; p pastes the perl code (so the original copy above can remain in the editor buffer); !Gperl runs the bottom of the file (the freshly pasted Perl code and the text to be filtered). G goes to the bottom of the results after filtering. For example, when processing error logs (which are usually too verbose for any one task), I'll trim the log repeatedly, often reusing parts of saved trimming code (in part because I prefer Perl regexes). Part of the value of this method is if I get such code wrong, I can just "u" (undo), adjust the code, and try again. (But I also often have filters that makes sense to apply more than once.)
- tye In reply to Re: Contribute a hack to the new "Perl Hacks" book (filter)
by tye
|
|