Date: 2008-11-23 04:10 pm (UTC)

It gives you a warning if you use warnings — otherwise that block silently goes on the else path. undef is actually fairly close to a NULL style value, can be used as that fairly easily. But there is no difference between having an undef value and not existing in the first place, unless you use strict (you should) which will gladly smack your fingernails if you use an undeclared variable. It should be noted that any and every variable declared will initially have an undef value.

ralesk@eretnek:~$ perl -e 'use warnings; undef $foo; if ($foo == 2) { print "do something\n"; }'
Use of uninitialized value $foo in numeric eq (==) at -e line 1.
ralesk@eretnek:~$ perl -e 'use strict; undef $foo; if ($foo == 2) { print "do something\n"; }'
Global symbol "$foo" requires explicit package name at -e line 1.
Global symbol "$foo" requires explicit package name at -e line 1.
Execution of -e aborted due to compilation errors.
ralesk@eretnek:~$ perl -e 'use strict; my $foo; undef $foo; if ($foo == 2) { print "do something\n"; }'
ralesk@eretnek:~$
This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

January 2026

S M T W T F S
     123
45678910
11121314151617
18192021222324
25262728293031

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags
Page generated May. 8th, 2026 08:48 pm
Powered by Dreamwidth Studios