in reply to Find common values in a hash and print the respective keys

If you want to avoid to build a hash of arrays, you could concatenate the key strings with a delimiter that does not exist in the values. Something like

my %rev; while( my( $key, $val) = each %hash ) { $rev{$val} .= "|$key"; }

Replies are listed 'Best First'.
Re^2: Find common values in a hash and print the respective keys
by LanX (Saint) on May 26, 2013 at 19:09 UTC
    Which is quite clever since keys must be strings. =)

    May I propose to put the delimiter at the end (splitting ignores by defaults empty fields at the end) ...

    DB<101> split /\|/, 'a|b|c|' => ("a", "b", "c") DB<102> split /\|/, '|a|b|c' => ("", "a", "b", "c")

    and to chose something less vulnerable like "\0" or "$;" as delimiter?

    Cheers Rolf

    ( addicted to the Perl Programming Language)