Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: $1, $2 not being set - array/scalar context confusion? Message-ID: <7505@jpl-devvax.JPL.NASA.GOV> Date: 22 Mar 90 01:00:55 GMT References: <1990Mar21.165957.9520@uvaarpa.Virginia.EDU> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 47 In article <1990Mar21.165957.9520@uvaarpa.Virginia.EDU> alfie%cs.warwick.ac.uk@nsfnet-relay.ac.uk writes: : There was recently a thread about a problem with $1 not being set when : a subroutine was called in an array context. I think I understood what : was happening. I am having a problem that is similar in some ways. : : What I would like, is either confirmation that I have discovered a bug : in perl (and that it will be fixed - Larry?), or that I have done : something silly, and an explanation of why, and how to avoid it. It is a bug, and will be fixed in patch 16. The problem is that perl was passing the desire for an array on to embedded BLOCKs that weren't in terminal statements. It shouldn't do that. (Of course, it shouldn't pass the desire for an array to a conditional expression in any event, but that's another problem.) By the way, I think you can simplify your routine a little: sub expand { local($tmp) = @_; $tmp =~ s/-/../g; local(@nums) = eval "($tmp)"; warn $@ if $@; @nums; } Alternately, there's sub expand { local($tmp) = @_; $tmp =~ s/(\d+)-(\d+)/join(',',$1..$2)/eg; warn "Illegal char '$1'" if $tmp =~ /([^\d,\s])/; split(',',$tmp); } or sub expand { local($tmp) = @_; local(@nums); push(@nums, $1 .. ($2?$3:$1)) while $tmp =~ s/^,?(\d+)(-(\d+))?//; warn "Don't recognize $tmp" if $tmp ne ''; @nums; } Depends on what you're optimizing for at the moment, I s'pose... Larry