... I'm not sure if I defined the empty-string key in the hash as you have asked me, did I do it correctly?

One way to see for yourself what a hash or array or arbitrarily complex structure of hashes and/or arrays contains is with the utility Data::Dumper, which IIRC is core and so should be supplied as part of any Perl installation, or with a similar utility such as Data::Dump, which I like. There are many other such utilities.

Do consider the documentation for index. Also consider the true/false values of the values index can return: -1 if a substring is not found, an offset of 0 or more if a substring is found; some simple experiments may help here.

Also perhaps consider if it's ever possible not to find the empty string in any other string, even in the empty string itself. Again, experimentation may be helpful.

I will have more time tomorrow to respond to the questions in your reply if others have not already done so. (Update: Actually, I could not say much more nor better than kcott does in his reply below.)


Give a man a fish:  <%-(-(-(-<


In reply to Re^6: find a substring of unknow lenght if it is in a hash by AnomalousMonk
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.