[ic] problem with new filter

Mike Heins mike at perusion.com
Fri May 7 16:54:31 EDT 2004


Quoting Eros Shop (info at eros-shop.co.uk):
> 
> 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:

We don't do filters that way any more, at least if this is 5.0.

CodeDef sentence Filter
CodeDef sentence Routine <<EOR
sub {
     my $val = shift;
     $val =~ m/^*\.//o;
     return $val;
}
EOR

Place that in a new directory code/local_function/sentence.filter
and restart IC. No muss, no fuss.

By the way, you don't want /o in your regex or you will potentially
have the wrong results if you call the filter more than once
between IC pages (or over multiple pages in PreFork mode).

And that regex is really no good, either. That is why it isn't
compiling. I am guessing you want:

	$val =~ s/(.*?)\..*/$1/;

-- 
Mike Heins
Perusion -- Expert Interchange Consulting    http://www.perusion.com/
phone +1.765.647.1295  tollfree 800-949-1889 <mike at perusion.com>

Friends don't let friends use Outlook. -- Bob Blaylock


More information about the interchange-users mailing list