Path: utzoo!attcan!uunet!samsung!aplcen!haven!uvaarpa!mmdf From: alfie%cs.warwick.ac.uk@nsfnet-relay.ac.uk (Nick Holloway) Newsgroups: comp.lang.perl Subject: Bug or misunderstanding? Message-ID: <2860@uvaarpa.virginia.edu> Date: 27 Feb 90 15:02:41 GMT Sender: mmdf@uvaarpa.virginia.edu Reply-To: alfie%cs.warwick.ac.uk@nsfnet-relay.ac.uk Lines: 48 [I am sending this via mailing list, since news is a bit dodgy here] I am trying to split an array into two arrays. One will contain any elements that match any pattern in a pattern array, and the other contains all others. Here is the section of code that is causing me grief: @text = ( "Hello", "Joe", "Schmoe", "Gordon" ); @pat = ( "e", "o" ); text: for $text ( @text ) { for $pat ( @pat ) { if ( $text =~ /$pat/i ) { print "Match: $pat: $text\n"; next text; } } print "NoMatch: $text\n"; } I know that I am using the same name in different contexts, but arrays, constants and labels should have a separate namespace (right?). The problem seems to be with the "next text;" line. I need that there, since otherwise elements may be matched with more than one pattern. I can't use a "last;" just to skip the rest of the patterns, coz I need to keep elements that do not match. However, the above code does not work as expected. Here is the sample output Match: e: Hello Match: o: Joe NoMatch: Schmoe Match: o: Gordon Note that "Joe" did not match on the "e" but on the "o", and "Schmoe" didn't match at all! Have I misunderstood something vital? This is my first attempt to use labelled "next/last"s, and it is possible I have missed something in the manual. If so, I am open to suggestions of better ways of doing it. Perhaps if I spell Randal's name wrong, he'll give me a one liner :-) At the moment, I am inclined to think it is a bug. BTW. This shows up in perl 3.0 patchlevel 8 on a Sun4. -- JANET : alfie@uk.ac.warwick.cs | `O O' | Nick Holloway BITNET/EARN : alfie%uk.ac.warwick.cs@ukacrl | // ^ \\ | Comp Sci Dept INTERNET : alfie%cs.warwick.ac.uk@nsfnet-relay.ac.uk | Uni of Warwick UUCP : ..!mcsun!ukc!warwick!alfie, alfie@warwick.UUCP | Coventry, UK.