Leser: 21
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/perl -w use strict; use diagnostics; my %hash; $hash{1}{2} = '123'; print "vorher:\n"; foreach my $xyz (sort {lc $a cmp lc $b} keys %hash) { print "$xyz=\'$hash{$xyz}\'\n"; } if (defined $hash{0}{2}) { } print "nachher:\n"; foreach my $xyz (sort {lc $a cmp lc $b} keys %hash) { print "$xyz=\'$hash{$xyz}\'\n"; }
2010-01-15T19:25:08 pqnennt sich autovivification.
2010-01-15T19:31:37 GwenDragonWenn du wissen willst, ob in einem Hash shon ein Eintrag ist, ohne ihn durch Perl automatisch erstellen zu lassen (Autovivication), musst du exists verwenden.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#!/usr/bin/perl -w use strict; use diagnostics; my %hash; $hash{1}{2} = '123'; print "vorher:\n"; foreach my $xyz (sort {lc $a cmp lc $b} keys %hash) { print "$xyz=\'$hash{$xyz}\'\n"; } if (exists $hash{0}{2}) { } print "nachher:\n"; foreach my $xyz (sort {lc $a cmp lc $b} keys %hash) { print "$xyz=\'$hash{$xyz}\'\n"; }
if ( exists $hash{0} and exists $hash{0}{2} ) ...