in reply to Combinatorics in Perl

Here's one regex (plus while loop) for it:

while ( s{ ^ (.*?) (\s* \S+)_DEL (.*) $ } {$1$3\n$1$2$3}xmg ) {}

I am trying to cook up one using (?{ ... }) constructs, but not having as much luck.

Update: Oops, left off the empty loop body...

Update (at 2004-04-29 23:49 -0700): Here is a more procedural solution that uses the same basic idea as above. It might be a bit more useful, as it returns a list of variants instead of one big string. (Would be interesting to benchmark them...)

sub del_selective { my $n = shift; if ( $n =~ m/(.*?)(\s*\S+)_DEL(.*)/s ) { my $s1 = $1.$3; my $s2 = $1.$2.$3; return ( del_selective( $s1 ), del_selective( $s2 ) ); } else { return ( $n ); } }

Replies are listed 'Best First'.
Re: Re: Combinatorics in Perl
by wouldbewarrior (Acolyte) on Apr 30, 2004 at 06:40 UTC
    Wow, I like it! That was very well done. I have this great big Japanese transcription database that some other engineers and I have been trying to use to cook up a speech recognizer for the language, but the transcription database has a bunch of crap in it. One way to fix this, for the recognizer is just to give it all available options, wherever there is ambiguous 'crap'. We were having a lot of trouble with this silly problem today though. So thanks a lot!
Re: Re: Combinatorics in Perl
by pizza_milkshake (Monk) on Apr 30, 2004 at 07:10 UTC
    argh, i worked for 2 hours and came up with nothing particularly useful. very nice job.

    perl -e'$_="nwdd\x7F^n\x7Flm{{llql0}qs\x14";s/./chr(ord$&^30)/ge;print'