|Do you know where your variables are?|
How do I create a simple, perl-based text filter for Vimby dimar (Curate)
|on Feb 13, 2005 at 17:12 UTC||Need Help??|
dimar has asked for the
wisdom of the Perl Monks concerning the following question:
Can someone provide a very simple proof-of-concept perl sample that works as a text filter for (g)Vim?
H is editing text with Vim. Vim can filter a region of text using (among other things) the built-in Vim-script language or an external program. H already has a trusty arsenal of perl scripts that can do various text-filtering operations, and H wants to use those instead of essentially re-writing them all in Vim-speak.
H is able to get Vim filtering to work with other external programs, but not with perl. For example:
The root of the problem appears to be that H cannot figure out how to get the input from Vim through STDIN.
H simply wants to see a bare-bones simple perl script that can filter text successfully from Vim (just like !sort can do) just to prove that it can indeed be done. It doesn't have to be sort, just something simple like:
NOTE: The previous code might as well be pseudocode, because it is not working. When run from Vim, the target text is not filtered, but simply blanked out. The _IT_WORKED_ tags do, however, appear.
NOTE: H has not been able to find any examples in the usual search venues.
NOTE: Alternate solution proposals are welcome, but see Constraints.
Update:Bingo. bmann and Re: Batch files in Win/Perl helped re-emphasize the long-known (yet forgotten) Windows bug ... pl2bat has a solution. Knee-jerk nauseated aversion to the words 'MSDOS' and 'batch' caused repressed memory syndrome...
20050219 Edit by castaway: Changed title from 'HOWTO: A simple, perl-based text filter for Vim'