Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!samsung!sdd.hp.com!elroy.jpl.nasa.gov!jpl-devvax!lwall From: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Newsgroups: comp.lang.perl Subject: Re: Is this a bug? Message-ID: <9105@jpl-devvax.JPL.NASA.GOV> Date: 10 Aug 90 22:34:55 GMT References: <1990Aug9.155120.2703@uvaarpa.Virginia.EDU> Reply-To: lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) Organization: Jet Propulsion Laboratory, Pasadena, CA Lines: 40 In article <1990Aug9.155120.2703@uvaarpa.Virginia.EDU> worley@compass.com writes: : I tried to write a program with the following regexp: : : /(^\s*$)|(^---)/ : : That is, match any line containing only whitespace, or beginning with : '---'. (Are ^ and $ allowed other than at the beginning or end of the : regexp?) Perl gives the strange error message: : : /(^\s*|(^---)/: unmatched () in regexp at ss line 3. : : Where did the missing ')' go? : : Actually, it was probably assumed to be part of a '$)' variable. (Can : one use '$/' as a variable is a regexp?) : : What is going on here? What *should* be going on here? It was misinterpreting $) in patterns as a variable. At patchlevel 27 it's interpreted correctly as an end of line check and a terminating paren. Which means you can't interpolate $) into a pattern directly. $/ has never been a problem. By the way, it's more efficient to factor out the ^ to the front: /^(\s*$|---)/ The reason for this is that it then knows it doesn't have to start looking at every single position of the input string. I suppose I should make it do this optimization itself... It's probably also faster to put the literal string before the *: /^(---|\s*$)/ This will be less of a problem after patchlevel 27, but it still helps some, unless almost all your strings are blank. Larry