The regex is a reference to earlier in the chapter, a duplicate word killer. After playing around with test patterns and test regex searches, I am not sure I really get what's going on above (perhaps it is just a lot to hit a weekend programmer like myself with at once ^_^). Here is what I think is going on: 1st regex) The while loop has a one because all the interesting stuff happens in the logical test. (\b(\w+) \1\b) matches a word boundary followed by one or more word characters followed by a space and whatever matched the (\w+). The match of (\w+) replaces the whole match. I think I kinda get it.$_ = "Paris in THE THE THE THE spring"; 1 while s/\b(\w+) \1\b/$1/gi;
Unfortunately I'm not really good enough to divine the difference between the two. Also, I don't see why the substitution that the book does doesn't eat up the preceding space: "Paris THE THE" turns into "ParisTHE". I hope I've a real conceptual problem here, and not just a brain fart, because I'll be feeling really sheepish asking if it is indeed a brain fart. Thanks in advance!/(\b\w+)\1\b
In reply to Prog. Perl 3rd Ed. Regex Question by makar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |