[ic] Chopping values

Jonathan Clark interchange-users@interchange.redhat.com
Tue May 28 07:53:01 2002


> > try [filter op=11]long text string[/filter]
> >
> > which would produce 'long text s' (first 11 characters). If you
>
> Thanks Jonathan for that tip :) The only problem is that it chops off in the
> middle of a word. Is there something that would chop at the first space?
> Unfortunately Perl is not (yet) my native language :)


ok. no problem.

Add the following to interchange.cfg:

GlobalSub <<EOR
sub new_filter {
    BEGIN {
	package Vend::Interpolate;
        $Filter{chop_boundary} = sub {
                        my $val = shift;
                        $val =~ s/(.+)\s.*/$1/;
                        return $val;
                        };
    }
}
EOR

restart ic, and then call with:

[filter op="10 chop_boundary"]long sentence to be chopped on a word boundary[/filter]

This should first truncate to 10, and then reduce to the last complete word (followed by whitespace). Output of above should be:

  long


Jonathan
Webmaint.