1
2
3
4
5
6
name |comment |para1 |para2
----------------------------------
abca |a_b__ca |1 |2
abcb |a_b__cb |7 |2
abcc |a_b__cc |4 |2
abcd |a_b__cd |9 |2
1 2 3 4 5 6
my %hash = ( abca => {comment => 'a_b__ca', para1 => 1, para2 => 2}, abcb => {comment => 'a_b__cb', para1 => 7, para2 => 2}, abcc => {comment => 'a_b__cc', para1 => 4, para2 => 2}, abcd => {comment => 'a_b__cd', para1 => 9, para2 => 2}, );
1 2 3 4 5 6
my %hash2 = ( a_b__ca => {comment => 'abca', para1 => 1, para2 => 2}, a_b__cb => {comment => 'abcb', para1 => 7, para2 => 2}, a_b__cc => {comment => 'abcc', para1 => 4, para2 => 2}, a_b__cd => {comment => 'abcd', para1 => 9, para2 => 2}, );
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/bin/perl use strict; use Data::Dumper; my %hash = ( abca => {comment => 'a_b__ca', para1 => 1, para2 => 2}, abcb => {comment => 'a_b__cb', para1 => 7, para2 => 2}, abcc => {comment => 'a_b__cc', para1 => 4, para2 => 2}, abcd => {comment => 'a_b__cd', para1 => 9, para2 => 2}, ); my %hash2; for (keys %hash) { my $tmp = $hash{$_}; $hash2{ $tmp->{'comment'} } = $tmp; $hash2{ $tmp->{'comment'} }->{'comment'} = $_; #delete $hash{$_}; } print Dumper %hash; print "-" x50; print Dumper %hash2;