Thread Hash Schlüssel tauschen
(1 answers)
Opened by MarkusH at 2014-01-18 12:01
Hi!
Code (perl): (dl
)
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; Ob das elegant ist vermag ich nicht zu beurteilen. Gruß Pörl.
|