[ic] problem with new filter
Mark Bryant
mark at vwe.net
Fri May 7 16:21:29 EDT 2004
At 20:22 07/05/2004, you wrote:
>At 07:22 PM 5/7/2004 +0100, you wrote:
>
>
>>Hi everyone,
>>
>>I'm having a spot of bother whilst trying to write a new [filter] op
>>that's supposed to return anything before and including the first "."
>>(dot) in the string passed to it.
>>
>>eg.
>>
>>[filter op=sentence]This is sentence one. This is sentence two.[/filter]
>>
>>returns: "This is sentence one."
>>
>>
>>Following the working example in the online docs, I've put this in my
>>interchange.cfg and tried to restart IC.
>>
>>GlobalSub <<EOR
>>sub new_filter {
>> BEGIN {
>> package Vend::Interpolate;
>> $Filter{sentence} = sub {
>> my $val = shift;
>> $val =~ m/^*\.//o;
>> return $val;
>> };
>> }
>>}
>>EOR
>>
>>Once the above is added IC refuses to start up giving the following error:
>>
>>Starting Interchange: Bad GlobalSub 'new_filter': Bareword "o" not
>>allowed while "strict subs" in use at (eval 124) line 6, <GLOBAL> line 17.
>>BEGIN not safe after errors--compilation aborted at (eval 124) line 9,
>><GLOBAL> line 17.
>>In line 17 of the configuration file '/etc/interchange.cfg':
>>GlobalSub <<EOR
>>
>>The original example for reverse I got from
>>http://www.icdevgroup.org/i/dev/docfly.html?mv_arg=ictags04%2e28 is fine
>>and IC loads up, so it must be my code that's at fault.
>>
>>Sadly my limited Perl knowledge doesn't permit me to understand the error
>>to know what I'm doing wrong here.
>>
>>I'd be very grateful if someone could point out my silly mistake(s) :)
>>
>>Many thanks
>>
>>Mark
>
>I'm no regex guru, but this may work better:
>
>GlobalSub <<EOR
>sub new_filter {
> BEGIN {
> package Vend::Interpolate;
> $Filter{sentence} = sub {
> my $val = shift;
> $val =~ s/\..*$/\./;
> return $val;
> };
> }
>}
>EOR
>
>Also, if you wrote this on a Windows box and uploaded it, you'll want to
>strip out any carriage returns from the file, as they could cause a problem:
>
> perl -i -p -e 's/\r//g' interchange.cfg
>
>- Ed
>
I found the final solution in:
GlobalSub <<EOR
sub new_filter {
BEGIN {
package Vend::Interpolate;
$Filter{sentence} = sub {
my $val = shift;
my $crap;
($val, $crap) = split (/(\. |\.<)/, $val);
$val = $val . ".";
return $val;
};
}
}
EOR
I had to take into account the opening brackets of HTML tags too ;)
Many thanks for your help
Mark
vwe internet ltd
EMail - info at vwe.net
WWW - http://www.vwe.net/
Tel - 0870 737 3369
Fax - 0870 737 4469
Tech Support - 0906 470 3369*
*UK only. Calls charged at 60p/min at all times
UK Broadband with modem, 2 filters and half price installation until
31/05/2004 - http://www.vwe.net/adsl
More information about the interchange-users
mailing list