Path: utzoo!attcan!uunet!samsung!zaphod.mps.ohio-state.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: <7521@jpl-devvax.JPL.NASA.GOV> Date: 23 Mar 90 17:35:05 GMT References: <1990Mar23.120241.20340@uvaarpa.Virginia.EDU> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 22 In article <1990Mar23.120241.20340@uvaarpa.Virginia.EDU> alfie%cs.warwick.ac.uk@nsfnet-relay.ac.uk writes: : sub expand { : local($tmp) = @_; : $tmp =~ s/\s+([-,])\s+/\1/g; # remove non-sep spaces : $tmp =~ s/\s+/,/g; # replace sep spaces with "," : $tmp =~ s/(\d+)-(\d+)/join(',',$1..$2)/eg; # perform range expansion : if ( $tmp =~ /([^\d,])/ ) { # check remainder is valid : warn "bad character '$1' in expand\n"; : $tmp = ""; # all bets are off! : } : split(',',$tmp); # split and return elements If you say print join(':',&expand('1, 2, 3 ,4')); you'll see that you have a bug. The first substitution only works if there's whitespace on both sides of the comma or hyphen. Changing the pluses to stars would fix that. Larry