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";
|
|---|