in reply to Remove duplicate key value pair in hash

Thank you very much for your quick responses. I know that these are distinct pairs. But for the case I'm considering, these are just plain strings and can be considered the same (duplicates) for all intents and purposes. Does it help ???

**UPDATE : I have now updated the example to illustrate one of the probs for the soln presented by YourMother. Is there a way to overcome this ??
  • Comment on Re: Remove duplicate key value pair in hash

Replies are listed 'Best First'.
Re^2: Remove duplicate key value pair in hash
by Anonymous Monk on Sep 19, 2014 at 19:33 UTC
    No, since you still haven't specified whether you mean that you want pairs such as (foo=>'bar',bar=>'foo') removed, or whether you consider "one" and "1" to be equal.
      I have modified the example now to remove the confusion. I hope it is clear now.

        If anything, it’s less clear to me… :P Examine this for a moment before you update or try to clarify–

        perl -MData::Dump=pp -e "pp {aaa=>'bbb', bbb=>'aaa', ccc=>'bbb', bbb=> +'ccc', abc=>'123'}" { aaa => "bbb", abc => 123, bbb => "ccc", ccc => "bbb" }

        Maybe hashes don’t work the way you think? You see the extra bbb key is already “deduplicated.”

        Update: and you silently updated the code in the OP… again. :(

Re^2: Remove duplicate key value pair in hash
by Laurent_R (Canon) on Sep 20, 2014 at 16:49 UTC
    Don't update and change the example, now the previous answers look incomprehensible. When you edit a post (especially a post that have received some answer), please don't change the content without explicitly saying what you changed or added.