perldoc perlsynvariable holds the undefined value ("undef") until it has been assigned a defined value, which is anything other than "undef". When used as a number, "undef" is treated as 0; when used as a string, it is treated as the empty string, ""; and when used as a reference that isn’t being assigned to, it is treated as an error.
2011-05-10T12:35:49 pqklar, das ist sogar guter stil, einfach:
2011-05-10T12:42:23 shi8daoIch programmiere normalerweise Sprachen, die so was komplizierter behandeln.
1 2 3 4 5 6 7 8 9
#!/usr/bin/perl -W use strict; use warnings; use Data::Dumper; my %hash; if (defined $hash{a} && defined $hash{a}{b}) {} print "Case 1 without autovivication:\n" , Dumper \%hash; if (defined $hash{a}{b}) {} print "Case 2 with autovivication:\n" , Dumper \%hash;
2011-05-10T12:53:17 biancaVielleicht sei an der Stelle eine Winzigkeit erwähnt:
Autovivifikation!
Siehe Code:
Code (perl): (dl )1 2 3 4 5 6 7 8 9#!/usr/bin/perl -W use strict; use warnings; use Data::Dumper; my %hash; if (defined $hash{a} && defined $hash{a}{b}) {} print "Case 1 without autovivication:\n" , Dumper \%hash; if (defined $hash{a}{b}) {} print "Case 2 with autovivication:\n" , Dumper \%hash;
Das muss man wissen, damit man nicht stolpert.
2011-05-10T13:06:59 shi8daoLiegt das jetzt an lazy evaluation?