in reply to Comparing strings to reduce excess results

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.

    Replies are listed 'Best First'.
    Re^2: Comparing strings to reduce excess results
    by Anonymous Monk on Sep 15, 2009 at 07:24 UTC
      A regular expression doesn't return an array (while would be neccessary for for(each)), it just returns true or false.

      It depends

      warn $_ for "one" =~ /./; warn $_ for "two" =~ /./g; warn $_ for scalar "two" =~ /./g; __END__ 1 at - line 1. t at - line 2. w at - line 2. o at - line 2. 1 at - line 3.