Ok, I need a bit of advice on how to attack this problem. I will construct the loop but need a little bit of help with proper syntax
assume, I got a substring and, a part of that str (like maybe 2 letters to 9 letters) can match an already existing key in a hash.
1. what I am unsure about is how to check each character in the string (substring) against the key in hash. proper syntax
2. what is the key if not provided to me yet , how to check this...
#implement learnings: #substring matching ~~ #incremental substring match against a key that may not be given yet. +return 0 learning... #maybe add counter of the times the substring match a key use strict; use warnings; use diagnostics; my %match: my @char; my $str = 'abcdefghjki'; #substr could match a 2 letter key or 10 letter to a hash key... my @char = split //, $str; #assigned string into array to check foreach my $key (keys %match){ if($match->[0] ~~ @char) # i don't know how to check an incremental t +est for the substring against the key in hash.don't know proper synta +x. { #do something } } #return num of times sub finds in for my $keys ($keys){ $match{$keys}++; print "this is the number of times we see for $keys :",$match{$k +ey},"\n"; }
In reply to find a substring of unknow lenght if it is in a hash by perlynewby
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |