Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Welcome to the Monastery
 
PerlMonks  

Re: how to use reversehash if there are more than one keys same

by indigo (Scribe)
on Sep 08, 2000 at 21:42 UTC ( [id://31688]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to how to use reversehash if there are more than one keys same

Assuming the keys of your input hash cannot contain the '|' character. Straight forward:
sub reversehash { my $href = shift; my %h; for (keys %$href) { my $v = $href->{$_}; if (exists $h{$v}) { $h{$v} .= "|$_"; } else { $h{$v} = $_; } } return \%h; }
To impress the chicks:
sub reversehash { my %h; push @{$h{$_[0]->{$_}}}, $_ for keys %{$_[0]}; $h{$_} = join '|', @{$h{$_}} for keys %h; return \%h; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://31688]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.