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

Re: Add characters to search value

by linuxer (Curate)
on May 22, 2009 at 00:32 UTC ( #765579=note: print w/ replies, xml ) Need Help??

in reply to Add characters to search value

What have you tried so far?

How did you implement the search?

#!/usr/bin/perl -l use strict; use warnings; my @names = ( 'Jones', 'Jones Jr', 'Jones Sr', 'Jones abc', 'Jones ', ); # may be filled from form value my $search = 'Jones'; my @regex = ( # simple qr{\Q$search\E}, # anchored qr{^\Q$search\E$}, # anchored and extended qr{^\Q$search\E(?:\s+\w+)?$}, ); for my $regex ( @regex ) { print "\n\n$regex"; for my $name ( @names ) { print "matched: $name" if $name =~ $regex; } } __END__

Beware; there's still room for improvement. Try that example and examine the results.

Comment on Re: Add characters to search value
Download Code
Replies are listed 'Best First'.
Re^2: Add characters to search value
by Anonymous Monk on May 22, 2009 at 18:13 UTC
    Thanks for your example and time. It helped me alot.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2016-02-07 06:44 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (249 votes), past polls