Perl String::Approx for values that taken from MySQL DataBase -


when apply string::approx values taken database, doesn't check matching words.

the program follows...

use string::approx qw (amatch); @matches = qw(); %matchhash = qw(); @x=$search_keyword; $i=0; $j=0; $l=1; $qry1="select * auctioncategoriesname"; $prp1 = $dbh1->prepare($qry1); $prp1->execute(); while(my $row1=$prp1->fetchrow_hashref()) {     $y=$row1->{'name'};     @name="(['$y'])";     @match = grep { amatch (@x, @$_) } @name;     $cnt=$#match;     if($cnt < 1)     {         $matches[$i]=$match[0];         $i++;     } } 

connections db perfect.

i want approximately matched names db amoung values present in $row1->{'name'}. values must kept stored in $matches[$i]. call values as:

foreach $k (@matches) { print "$k <br/>" } 

as richard said line unnecessary :-

@name="(['$y'])"; 

you write $y , perl right thing.

the grep followed if duplication of same work. amatch returns true/false in scalar context can use that.

you simplify code along these lines :-

  1 use string::approx qw (amatch);   2 use strict;   3 @matches = qw();   4 $search_keyword = 'hello';   5 foreach $y ('hello', 'world')   6 {   7     if (amatch ($search_keyword, ($y)))   8     {   9         push @matches, $y;  10     }  11 }  12   13 print @matches 

the output :-

$ perl test.pl hello 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -