Keep It Simple, Stupid | |
PerlMonks |
Re: regex on a lineby Basilides (Friar) |
on Aug 01, 2002 at 16:40 UTC ( [id://186829]=note: print w/replies, xml ) | Need Help?? |
There're a quiet a few bugs in this, and I think you'd really benefit from putting use strict at the top of your programs. Anyway, you're missing a curly bracket, and you've spelt "view" wrongly in your print statement, so you'd never get a proper result. Also, the string you're trying to match: "(view: pa_Iden etc etc)" has got spaces in it, so you'll never succeed in your match if you use the non-whitespace character, \w. You could substitute that for "." which matches anything, although I have heard monks say that ".*" is bad practice (I'm still quite a novice tho', so I don't know why they say this!). Finally, when you assign to $view, you mean $2, not $1. You could do with taking out some of those brackets, which are confusing you with backreferences. Here's a version which works: However, here's a slightly more concise version which only uses one regex: Note that in each of these, as soon as an "Update: open" line is found, the file is closed. I don't know if that's what you want, but if not, you'll have to move that close(check); line.
HTH
In Section
Seekers of Perl Wisdom
|
|