Thread Speichern von Daten aus array in Hash: %hash und @array/aref (6 answers)
Opened by Duff at 2007-05-25 16:48

bloonix
 2007-05-26 04:01
#76962 #76962
User since
2005-12-17
1615 Artikel
HausmeisterIn
[Homepage]
user image
Just an example:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
use strict;
use warnings;
use Data::Dumper;

my @array = (
  'Schlüssel1    Wert1 Wert2',
  'Schlüssel2    Wert3',
  'Schlüssel3    Wert4 Wert5',
  'Schlüssel4    Wert6 Wert7',
);

my %hash;

foreach my $line (@array) {
  my ($key, @values) = split /\s+/, $line;
  $hash{$key} = \@values;
}

print Dumper(\%hash);
\n\n

<!--EDIT|opi|1180138941-->
What is a good module? That's hard to say.
What is good code? That's also hard to say.
One man's Thing of Beauty is another's man's Evil Hack.

View full thread Speichern von Daten aus array in Hash: %hash und @array/aref