Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!uflorida!haven!uvaarpa!mmdf From: alfie%cs.warwick.ac.uk@nsfnet-relay.ac.uk (Nick Holloway) Newsgroups: comp.lang.perl Subject: Re: $1, $2 not being set - array/scalar context confusion? Message-ID: <1990Mar23.120241.20340@uvaarpa.Virginia.EDU> Date: 23 Mar 90 12:02:41 GMT Sender: mmdf@uvaarpa.Virginia.EDU (Uvaarpa Mail System) Reply-To: alfie%cs.warwick.ac.uk@nsfnet-relay.ac.uk Organization: The Internet Lines: 33 In comp.lang.perl, lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: | It is a bug, and will be fixed in patch 16. It's nice to know that my brain hadn't fried, and that I was not misunderstanding what should happen (and to hear the magic words "will be fixed"). | By the way, I think you can simplify your routine a little: I had thought I had seen smaller routines to do the job, but that was before I became a perl addict. I can see how all three routines work, but I think I prefer the 2nd (purely subjective - I have not let matters like performance cloud the issue :-). My original version allowed you to use either a space or comma to separate the terms (so "1 3 - 5" is the same as "1,3-5"), and to return an empty array upon finding an error, so here is Larry's version 2 of expand with these spliced back in. Cheers, Larry, for the smaller routine. 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 } -- Nick Holloway | `O O' | alfie@cs.warwick.ac.uk, alfie@warwick.UUCP, [aka `Alfie'] | // ^ \\ | ..!uunet!mcsun!ukc!warwick!alfie