Leser: 18
1 2 3 4 5 6 7 8
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my %tabelle; $tabelle{head}{(keys %{$tabelle{head}}) + 1} = 'foo'; $tabelle{typ}{(keys %{$tabelle{typ}}) + 1} = 'N'; $tabelle{head}{(keys %{$tabelle{head}}) + 1} = 'bar'; $tabelle{typ}{(keys %{$tabelle{typ}}) + 1} = 'A'; print Dumper(%tabelle);
1 2 3 4 5 6 7 8
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my %tabelle; push @{ $tabelle{head} }, 'foo', 'bar'; push @{ $tabelle{typ} }, 'N', 'A'; print Dumper(%tabelle);
1 2 3 4 5 6 7 8 9
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my %tabelle = ( head => [qw/foo bar/], typ => [qw/N A/] ); print Dumper(%tabelle);
2010-03-27T11:51:58 esskarwie benutzt du hash-of-hash und nicht hash-of-array?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my %tabelle; foreach my $line (split /\n/,<<KONSTANTE foo N bar A KONSTANTE ) { $line =~ s/\t\t/\t/g while $line =~ /\t\t/; ( $tabelle{head}{(keys %{$tabelle{head}}) + 1}, $tabelle{typ}{(keys %{$tabelle{typ}}) + 1}, ) = split /\t/,$line; } print Dumper(%tabelle);
( ... ) = split /\t+/, $line;
2010-03-27T12:14:43 reneewürde ich eherschreibenCode (perl): (dl )( ... ) = split /\t+/, $line;
2010-03-27T11:58:11 biancaIch würde es trotzdem machen...2010-03-27T11:51:58 esskarwie benutzt du hash-of-hash und nicht hash-of-array?
Ist unübersichtlich. Meine Werte sind nicht so kurz wie foo und bar.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my %tabelle; foreach my $line (split /\n/,<<KONSTANTE foo N bar A KONSTANTE ) { my ($head,$typ) = split /\t+/, $line; push @{ $tabelle{head} }, $head; push @{ $tabelle{typ} }, $typ; } print Dumper(%tabelle);
2010-03-27T12:16:26 reneeIch würde es trotzdem machen...
1
2
3
4
5
6
7
8
9
10
$VAR1 = 'head';
$VAR2 = {
'1' => 'foo',
'2' => 'bar'
};
$VAR3 = 'typ';
$VAR4 = {
'1' => 'N',
'2' => 'A'
};
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my %tabelle; foreach my $line (split /\n/,<<KONSTANTE foo N bar A KONSTANTE ) { my ($head,$typ) = split /\t+/, $line; my $counter = scalar keys %{ $tabelle{head} || {} }; $tabelle{head}->{$counter} = $head; $tabelle{typ}->{$counter} = $typ; } print Dumper(%tabelle);
2010-03-27T12:22:38 reneeDann ist aber nicht mehr "Unübersichtlichkeit" der Grund...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my %tabelle; my $trenner = $/; foreach my $line (split /$trenner/,<<KONSTANTE foo N bar A KONSTANTE ) { my $counter = (keys %{$tabelle{head}}) + 1; ($tabelle{head}->{$counter},$tabelle{typ}->{$counter}) = split /\t+/,$line; } print Dumper(%tabelle);
1 2 3 4 5 6
split m!$/!, <<KONSTANTE; KONSTANTE # vs split "$/", <<KONSTANTE; KONSTANTE
2010-03-27T12:35:04 reneeDiese zwei Varianten sollte es tun:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#!/usr/bin/perl -w use strict; use warnings; use Data::Dumper; my %tabelle; foreach (split m!$/!, <<KONSTANTE foo N foo2 X bar A KONSTANTE ) { my $counter = (keys %{$tabelle{head}}) + 1; ($tabelle{head}->{$counter},$tabelle{typ}->{$counter}) = split /\t+/,$_; } print Dumper(%tabelle);