Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!caesar.cs.montana.edu!ogicse!hakanson From: hakanson@ogicse.ogc.edu (Marion Hakanson) Newsgroups: comp.lang.perl Subject: Re: Subroutines Returning Null Arrays Message-ID: <6712@ogicse.ogc.edu> Date: 18 Jan 90 18:11:26 GMT References: <13395@cit-vax.Caltech.Edu> Reply-To: hakanson@ogicse.UUCP (Marion Hakanson) Organization: Oregon Graduate Institute (formerly OGC), Beaverton, OR Lines: 48 In article <13395@cit-vax.Caltech.Edu> joe@cit-750.cs.caltech.edu (Joe Beckenbach) writes: > > Is there a way to force a subroutine to return a null array? Now that you mention it, I've been wondering about some odd behavior related to that for awhile. I have a workaround, and I forgot to track it down further. Here's the workaround: while ( (@a = do subr()) && @a ) { # fiddle with @a } Now I just tracked it down further. Here's a test program which demonstrates the problem (perl 3.0, pl6, anyway -- I didn't notice a patch in 7&8): ==========cut here=========== #!/usr/bin/perl sub nsub1 { (); } sub nsub2 { return (); } @nr1 = do nsub1(); print "nr1 has $#nr1 elements.\n"; @nr2 = do nsub2(); print "nr2 has $#nr2 elements.\n"; ==========cut here=========== Here's the output: nr1 has -1 elements. nr2 has 0 elements. It turns out that $nr2[0] is empty, which is why my "workaround" works. Definitely looks like a bug to me, though. Larry? -- Marion Hakanson Domain: hakanson@cse.ogi.edu UUCP : {hp-pcd,tektronix}!ogicse!hakanson