Embedding a Perl filter

Get help using and writing Nisus Writer Pro macros.
Post Reply
js
Posts: 259
Joined: 2007-04-12 14:59:36

Embedding a Perl filter

Post by js »

To sort paragraphs and kill duplicate lines I normally use a Perl macro like this

Code: Select all

use strict;
my %seen;
while (<>) {
    $seen{$_}++;
}
print sort keys %seen;
I tried to integrate this into a Nisus macro like this:

Code: Select all

Begin Perl
my perl macro
End
But this does not work. What should I have done?
Is there maybe a Nisus macro which does the same thing?
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Embedding a Perl filter

Post by Kino »

If you don't need exchanging data between a Perl block and other parts of the same Nisus macro and if you just want to replace a selection with the output of your perl script, then I think you'd better write it as a Perl macro (with pl as file extension), not as a Nisus macro.

Code: Select all

#Nisus Macro Block
#source front selection
#destination clipboard
#after execution
#Paste
#End Nisus Macro Block

my %seen;
while (<STDIN>) {
	$seen{$_}++;
}
print sort keys %seen;
js wrote:Is there maybe a Nisus macro which does the same thing?
The simplest Nisus Writer Pro way would be...

Code: Select all

Menu ':Edit:Sort Paragraphs:Ascending (A-Z)'
Replace All '(^.*\n)\1+', '\1', 'E-is'
js
Posts: 259
Joined: 2007-04-12 14:59:36

Re: Embedding a Perl filter

Post by js »

Thank you, Both work fine now.

I found BTW that in the case of the Perl macro, even without using it with additional Nisus code, I had to add a Start Perl / End line to make it work.
Kino
Posts: 400
Joined: 2008-05-17 04:02:32

Re: Embedding a Perl filter

Post by Kino »

js wrote:I found BTW that in the case of the Perl macro, even without using it with additional Nisus code, I had to add a Start Perl / End line to make it work.
That means that you saved it as a Nisus Macro (filename.nwm). If it were a Nisus Perl Macro (filename.pl), "Begin Perl ... End" should have yielded an error.
Post Reply