in reply to Parsing an Array of Hashes, Modifying Key/Value Pairs

Your usage of grep is incorrect. In your first script, use

if ( !grep(/$key/, @keysToKeep) )

to make it work.

Replies are listed 'Best First'.
Re^2: Parsing an Array of Hashes, Modifying Key/Value Pairs
by LanX (Saint) on May 12, 2013 at 18:50 UTC
    > if ( !grep(/$key/, @keysToKeep) )

    Careful! Without anchors you'll also match on substrings, so better /^$key$/.

    Anyway try to avoid regexes when possible and use eq

    if ( not grep { $key eq $_ }  @keysToKeep) )

    Cheers Rolf

    ( addicted to the Perl Programming Language)

    edit

    corrected code

      Good catch!
      When I'm playing with regex, I use GSkinners test suite (as I'm without a doubt, no wizard)
      The regex fail in the OP was very much glassed over by me as I knew it wasn't doing anything that was getting me towards my end goal.
      http://gskinner.com/RegExr/

      -- Libra