Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!bu.edu!nntp-read!composer From: composer@chem.bu.edu (Jeff Kellem) Newsgroups: comp.lang.perl Subject: Re: defined() - bug or feature? Message-ID: Date: 21 Mar 91 19:52:31 GMT References: <1991Mar21.142935.11333@bmers145.bnr.ca> Sender: news@bu.edu.bu.edu Reply-To: composer@chem.bu.edu Organization: Boston University Chemistry Department Lines: 37 In-reply-to: friedman@chekov.UU.NET's message of 21 Mar 91 14:29:35 GMT In article <1991Mar21.142935.11333@bmers145.bnr.ca> friedman@chekov.UU.NET (Barry Friedman) writes: > I've noticed the following non-intuitive behaviour of 'defined()': > When a variable is used in a string it becomes defined. > > I don't recall any discussion on this. > > #!/usr/bin/perl > > $a='$b is undefined'; > $a='$b is defined' if defined ($b); > print $a,"\n"; > print "b is now <$b>","\n"; > $a='$b is defined' if defined ($b); > print $a,"\n"; > __END__ > > produces > $b is undefined > b is now <> > $b is defined From the man page (actually my Texinfo conversion of the man page) under the section titled "Data Types and Objects", "...An undefined null string may become defined the first time you access it, but prior to that you can use the `defined()' operator to determine whether the value is defined or not." Therefore, accessing "$b" in the line `print "b is now <$b>", "\n";' makes $b defined instead of undefined. Cheers... -jeff Jeff Kellem Internet: composer@chem.bu.edu