Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Merge hash keys

by hdb (Monsignor)
on Oct 30, 2013 at 11:54 UTC ( [id://1060342]=note: print w/replies, xml ) Need Help??


in reply to Merge hash keys

Instead of substr you could also use regular expressions. Concatenate all your strings in the correct order with a delimiter character that is not part of the strings, eg. #. Then find the same sequence of characters to the left and right of each delimiter and remove one side. It could look like this:

my %hash = ( anee => '1', jane => '0', neen => '2', ); my $merge = join '#', sort { $hash{$a} <=> $hash{$b} } keys %hash; $merge =~ s/([^#]*)#(?=\1)//g; print "$merge\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1060342]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-24 22:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found