Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Regexp::Approx - Use fuzzy regular expressions

by Anonymous Monk
on Nov 12, 2003 at 07:37 UTC ( [id://306490]=note: print w/replies, xml ) Need Help??


in reply to Regexp::Approx - Use fuzzy regular expressions

It seems that your "fuzzy" regex isn't much different from just using dot and the length of the target. That is:

#!/usr/bin/perl -w use strict; use lib '.'; use Regexp::Approx 'fuzzy_qr'; use re 'eval'; while(<DATA>) { chomp; print "Using '$_' as fuzzy component:\n"; my $fuzzy_part = fuzzy_qr( $_ ); my $rx = qr/((?:$fuzzy_part\s)?\w+\d)$/; if ( "5678 DELAWARE AVENUE AOT 123" =~ $rx ) { print "\tRX Match: $1\n"; } my $really_fuzzy = '.{' . length($_) . '}'; my $rfx = qr/((?:$really_fuzzy\s)?\w+\d)$/; if ( "5678 DELAWARE AVENUE AOT 123" =~ $rfx ) { print "\tRFX Match: $1\n"; } } __END__ APT XXX ^%@#!( fuzzy matches anything? x # output: Using 'APT' as fuzzy component: RX Match: AOT 123 RFX Match: AOT 123 Using 'XXX' as fuzzy component: RX Match: AOT 123 RFX Match: AOT 123 Using '^%@#!(' as fuzzy component: RX Match: UE AOT 123 RFX Match: UE AOT 123 Using 'fuzzy matches anything?' as fuzzy component: RX Match: 678 DELAWARE AVENUE AOT 123 RFX Match: 678 DELAWARE AVENUE AOT 123 Using 'x' as fuzzy component: RX Match: T 123 RFX Match: T 123

Replies are listed 'Best First'.
Re: Re: Regexp::Approx - Use fuzzy regular expressions
by diotalevi (Canon) on Nov 12, 2003 at 14:32 UTC

    Drat. I musta screwed up the failure case while working on the send/recv functions. It did work correctly before. Fixes to come in an hour or so.

    Got it. The code was testing the return value of print() instead of the actual match response. When I added the general function wrapper I forgot to put a `return _read_msg()` in. (Again) it works correctly for me using your sample script.

      There seems to be remaining problems, for example:

      #!/usr/bin/perl -w use strict; use lib '.'; use Regexp::Approx 'fuzzy_qr'; use re 'eval'; while(<DATA>) { chomp; print "Using '$_' as fuzzy component:\n"; my $fuzzy_part = fuzzy_qr( $_ ); my $rx = qr/($fuzzy_part)/; if ( "5678 DELAWARE AVENUE AOT 123" =~ /$rx/ ) { print "\tRX Match: $1\n"; } } __END__ APT A XXX ^%@#!( fuzzy matches anything? x #### output: Using 'APT' as fuzzy component: RX Match: AO Using 'A' as fuzzy component: RX Match: 5 Using 'XXX' as fuzzy component: amatch: $_ is undefined: what are you matching? Compilation failed in require at xxx.pl line 4, <GEN0> line 51. BEGIN failed--compilation aborted at xxx.pl line 4, <GEN0> line 51. Using '^%@#!(' as fuzzy component: Broken pipe ### platform: $ perl -v This is perl, v5.8.0 built for i686-linux

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://306490]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (6)
As of 2024-04-18 06:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found