Thread Hash Schlüssel tauschen (1 answers)
Opened by MarkusH at 2014-01-18 12:01

styx-cc
 2014-01-18 12:34
#173063 #173063
User since
2006-05-20
533 Artikel
BenutzerIn

user image
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.

View full thread Hash Schlüssel tauschen