in reply to defined vs null string
will give you whatever junk is in memory, it is unlikely that the value will be zero. In Perl we don't have that problem, every scalar has the value undef until you assign it otherwise. This can be flagged as an error or warning should you want it (that's one reason for use warnings and use strict).int x; printf("%d",x);
could cause printf to run into an address which is illegal and crash the program. It might not - it might hit a zero delimiter by coincidence, but then you get junk displayed. No such problems in Perl.char name[42]; printf("%s",name);
See the difference between setting a string to be empty and using undef. Would it have made a difference if you assigned undef to the string instead of using undef as a function?use strict; use warnings; use Devel::Peek; my $str = ""; Dump($str); $str = "Fred Bloggs"; Dump($str); $str = "This is a much, much longer string"; Dump($str); $str = ""; Dump($str); undef $str; Dump($str);
|
|---|