Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!ub!uhura.cc.rochester.edu!ee.rochester.edu!moscom!wjb From: wjb@moscom.UUCP (Bill de Beaubien) Newsgroups: comp.lang.perl Subject: Pattern matching Message-ID: <2799@moscom.UUCP> Date: 12 Jun 91 13:06:16 GMT Reply-To: wjb@moscom.UUCP (Bill de Beaubien) Organization: Moscom Corp., E. Rochester, NY Lines: 23 While working on a Perl script a little while back, I found myself trying to substitute occurances of the contents of a variable with nothing. This is a straight-forward thing, except that the string I was trying to match on contained parentheses, which Perl took as RE parens rather the text parens. Easy enough to solve, but the solution I came up with just didn't appeal to me esthetically; it seems kind of bulky, and I have to wonder if there isn't a better way. So, tell me... is there a better way? This is the code I came up with; The list I'm trying to remove from is in $nodes{$elt}, and the pattern I'm trying to remove is in $elt. ... $nodes{$elt} .= join(" ",@list); $ptrn=$elt; $ptrn=~s/([\(\)])/\\$1/g; ($nodes{$elt}) =~ s/(.*)$ptrn(.*)/$1$2/ ... -- "Bless me, Father; I ate a lizard." "Was it an abstinence day, and was it artificially prepared?" ------------------------------------------------------------- Bill de Beaubien / wjb@moscom.com