Path: utzoo!censor!geac!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!tut.cis.ohio-state.edu!sei!fs7.ece.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 22:05:53 GMT Organization: Carnegie Mellon, Pittsburgh, PA Lines: 88 In article <11125@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: >: References to arrays (shift, pop) apparently always ignore null >: elements (while references to lists [for, grep] do not), > >I don't think this is true either. If you shift an undefined element out >of an array, you get an undefined value. Can you give an example of what >you mean? That part shouldn't have been in there... It was more-or-less thinking "out loud." It was really just a summary of the behavior of the iterative operators and how they acted on such a list: sub function { (); } # prints nothing (really a function of while test) @x = (&function())[7,8]; while (shift @x) { print "shift: yes\n"; } # prints nothing (really a function of while test) @x = (&function())[7,8]; while (pop @x) { print "pop: yes\n"; } # prints twice for ((&function())[7,8]) { print "for: yes\n"; } # prints just once -- why? grep(print, "grep: yes\n", (&function())[7,8]); >It might just be possible to make slices discard any *trailing* undefined >elements, but that might cause other surprises. I'd have to think about >that a lot. > >Alternately, it might be possible to make array assignment in a scalar >context not count any trailing undefined values on the RHS, but again, >that's a very dangerous kind of semantic change. Doesn't PERL distinguish undefined variables from those whose values are "undef?" If so, an element of an array slice should have the value of the requested element if it has one (could be undef), or remain undefined. For the scalar context of list assignment, only those values (defined or undefined) up to and including the last defined value can be counted for the value of the expression, giving you a better picture of what was available for assignment. I THINK everything would be ok; I thought there was a difference between being undefined and just having the value "undef." The following script prints both lines, no matter which of the two assignments is used. #($a,$b) = (1); ($a,$b) = (1,undef); print '! defined $b', "\n" unless defined $b; print '! $b', "\n" unless $b; Also, interestingly, the following script print $], "\n"; print(($a,$b,$c) + 0, "\n"); $b = 1; print(($a,$b,$c) + 0, "\n"); $c = 1; print(($a,$b,$c) + 0, "\n"); prints $Header: perly.c,v 3.0.1.9 90/11/10 01:53:26 lwall Locked $ Patch level: 41 0 0 1 I realize that I could still be confused about this issue, and I appreciate your time and effort in analyzing this situation. I hope I'm not wasting anyone's time, but I would like to resolve the issue. Rudy +---------+ : +-----+ : Rudy Maceyko : : +-+ : : rm55+@andrew.cmu.edu : : : +-+ : rtmst@cis.pitt.edu +-+ +-+-+-+