I need help understanding a warning I got and correct my syntax on the ~~ operator match.
Also, I appreciate any commnents on the code and method(improving, provide possible oversight on code, etc..)
Again, I am learning so much with all of your help and advice
find myself liking Perl...today ;-)
question 1 I don't understand why on INDEX, the warning says $string is undef? and I also had to declare it again as "my" when I did on pragma.
question 2 whys is the '~~" operator method it's not working
use strict; use warnings; use diagnostics; my @char; my $art; my $string = 'abcdefghijk'; my %match = (bc => "Michelangelo", efg => "Raffaello",de => "Caravaggi +o",ijk => "Tintoretto",hij=>"Leonardo",); @char = split //,$string; #check that the substring is in hash; foreach $art (keys %match){ if ($string=~/$art/){ print "There's a match in the string to $art =>", $match{$art}++ +,"\n"; } } #now using GREP foreach $art (keys %match){ if (my $seen= grep {$string =~ $art}$match{$art}) { print "I have seen using GREP $art=>",$match{$art},"\n"; } } #using ~~ match operator foreach $art (keys %match){ print "this is \~~ $art=> ",join('',$match{$art}) if /$string/i ~~$art +; } #using INDEX() foreach $art (keys %match){ print "this is INDEX $art =>",join('',$match{$art}),"\n", if index + my $tring,$art; }
In reply to Re: find a substring of unknow lenght if it is in a hash
by perlynewby
in thread find a substring of unknow lenght if it is in a hash
by perlynewby
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |