[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: [OT] Perl: exec and $variables



On Sat, Jul 21, 2001 at 04:53:35PM +0200, Joost Kooij wrote:
> What is the need for the seperate variable $BEGINREGEX?  It
> complicates things enormously when you want a variable $no to be
> evaluated whenever $BEGINREGEX is evaluated.  The only sane way out is
> to completely reevaluate $BEGINREGEX after each change to $no.  To do
> that successfully, you have to escape '$', '"', and '\' and then
> escape some of the escapes, but others not, depending on wheter they
> should never be expanded, expanded in the eval or expanded when
> applying the regexp.  I wouldn't touch that with a ten foot pole if I
> were you.  If you succeed at it, you have great job security, and a
> maintenance nightmare.

Right, I agree.

> Easier is to not use a $BEGINREGEX at all:
> 
>   $line =~ m(^<!-- // begin of news$no // !-->$);
> 
> should always work, for the current value of $no.

Which is what I ended up doing.

I made a function getBeginRegex() and getEndRegex() which return the
string I then use as a regex for searching.
This way I don't have to write the regex string many times over in the
program, which is what I was trying to avoid when I did the $BEGINREGEX
thing.

Thanks a lot for your help!

Sven



Reply to: