A regular expression doesn't return an array (while would be neccessary for for(each)), it just returns true or false. You could use while for this:
foreach $node (keys(%current)) { if ($current{$node} eq "created") { foreach $node2 (keys(%prior)) { while ($node2 =~ m/\/.+(\S)/) {
Sorry, but I don't understand what you're trying to do with the next two lines. The if would never match. Here is what you're doing:
  • Match some regexp against $node and remember the last whitespace char
  • String-Compare the result of the regexp (1=true or 0=false) to the remembered whitespace
  • This won't ever match, sorry.

    Here is my solution for your approach:

    for $node (keys(%current)) { if ($current{$node} eq "created") { ++$Created; } elsif ($current{$node} eq "deleted") { ++$Deleted; } }
    (There are shorter variants, but we want to stay easy and readable.)
    If you don't know if one was created or deleted, cross-check with the second hash:
    for $node (keys(%current)) { defined($prior{$node}) or ++$Created; } for $node (keys(%prior)) { defined($current{$node}) or ++$Deleted; }
    This runs through the first hash and looks if the same entry exists in the prior hash. If there is no such hash key, it counts the node as new.
    The same for the deleted, but this time we check all nodes from the last run and look if they still exist in the current run.

    I still don't understand what you were trying to do with your source, maybe it's still too early morning here. :-) It would be good for helping you, if you could add some more text and/or comments.


    In reply to Re: Comparing strings to reduce excess results by Sewi
    in thread Comparing strings to reduce excess results by grub_

    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.