>>>>> "RN" == Ron Newman <[EMAIL PROTECTED]> writes:
RN> I've never really understood the rules for when it's "OK" to use
RN> undef as if it were 0 or "", and when it is "not OK" (generates a
RN> warning). Can someone summarize them, or point me to a reference?
without warnings enabled you can always use undef and it will be coerced
to 0 or '' as needed. this is good for one liners and golf and such
things. there are a couple of very useful places where i know undef gets
converted to '' and 0 without warnings.
++ and += are the numeric place:
perl -lwe '$i++ ; print $i'
1
perl -lwe '$i += 1 ; print $i'
1
perl -lwe '$i = $i + 1 ; print $i'
Use of uninitialized value in addition (+) at -e line 1.
1
and similarly . and .= do that too (note that . needs the undef on the
left side):
perl -lwe '$i .= "x" ; print $i'
x
perl -lwe '$i = $i . "x" ; print $i'
x
perl -lwe '$i = "x" . $i ; print $i'
Use of uninitialized value in concatenation (.) or string at -e line 1.
x
there may be a few others and this isn't well documented if at all. some
would call the . and += a bug but not ++ and .=
i use .= all the time and in general never initialize the value to ''
(even when using it in a hash like $foo{text} .= 'bar').
uri
--
Uri Guttman ------ [EMAIL PROTECTED] -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm