Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!zaphod.mps.ohio-state.edu!usc!ucsd!rutgers!rochester!pt.cs.cmu.edu!o.gp.cs.cmu.edu!andrew.cmu.edu!rm55+ From: rm55+@andrew.cmu.edu (Rudolph T. Maceyko) Newsgroups: comp.lang.perl Subject: Re: null? or not null? Message-ID: Date: 20 Jan 91 00:25:34 GMT References: , Organization: Carnegie Mellon, Pittsburgh, PA Lines: 49 In-Reply-To: flee@cs.psu.edu (Felix Lee) writes: > > print 2 if ($a,$b) = undef; # prints 2 -- why? > > "undef" is not a null list. "()" is a null list. "undef" is the same > as "(undef)". If you try That's true, and I see why the assignment of "undef" to the list returns true, but I still would like the the following while loop to terminate if the function returns "()" (not "undef," as I stated previously) instead of iterating indefinitely. while (($a,$b) = (&function())[7,8]) { ... } I understand that "mentioning" non-existent array elements causes their creation, but is that entirely necessary when the array is empty and only referred to? Unless it causes trouble that I don't forsee, I would consider "ignoring" such array slices of "()" both a feature and an optimization. It's a feature because it makes my scripts work ;-> and an optimization because creating new elements for the null list in this case accomplishes nothing. References to arrays (shift, pop) apparently always ignore null elements (while references to lists [for, grep] do not), and conditionality is apparently processed as a list (in an "array" context). Hmmm.... A kludge which does what I want is: sub function { (); } while (($a,$b) = (@_ = &function())[7,8], @_) { print "yes\n"; } but that involves the extra assignment and testing. Do I have to live with the kludge, or am I talking about a viable addition to the language? Rudy +---------+ : +-----+ : Rudy Maceyko : : +-+ : : rm55+@andrew.cmu.edu : : : +-+ : rtmst@cis.pitt.edu +-+ +-+-+-+