I am using merlyn's/perlmonkey's solution on how to match comments and quotes. When I do the following:
%hash = ('"', '"', '/*', '*/', '<-', '->'); foreach (keys(%hash)) { $start = $_; $end = $hash{$_}; my $inside = 0; my $oldpos = 0; while ($string =~ /(?<!\\)(\Q$start\E|\Q$end\E)/g) { if ($inside == 0) { $oldpos = pos($string) - length($start); $inside++; } else { push (@a, substr($string, $oldpos, pos($string)-$oldpos)); $inside--; } } }
the code works and @a gets all the matches.
But when I create my %hash differently, like:
while($db->FetchRow()) { undef %mult; %mult = $db->DataHash(); push (@multy, values(%mult)); } %hash = reverse(@multy);
and then run the same code as above, my $string gets split by character, and each element of @a receives a single character.
What's the difference and how do I fix that?

In reply to strange hash behavior by Eugene

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.