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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.