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

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.