in reply to Re: Regex frustration
in thread Regex frustration

Did you test this? It doesn't work on my system.

C:\test>type fred.pl $exp = qr|^DMSC0022\s+\S+\s+(\w+)$|; $str = 'Logfile_Connection_Lost Hostname: $1'; # note that you have to + use single quotes or the $1 is interpolated as soon as you de fine $str, not when you eval() the string (which is completely superfl +uous) $_ = "DMSC0022 X10 oswald"; if ($exp) { print eval $str; # *now* get $str to interpolate } C:\test>fred Use of uninitialized value in print at C:\test\fred.pl line 6. C:\test>

Replies are listed 'Best First'.
Re: Re: Re: Regex frustration
by diotalevi (Canon) on Sep 25, 2002 at 02:16 UTC

    No, I'm an idiot and didn't. What I initially wrote was buggy and didn't work. Two problems: the expression wasn't being evaluated properly and the eval wasn't done correctly. The *right* way to do that eval (though an eval() isn't right in this case at all) was to do eval "print \"$str\"";.

    So my bad. I fixed the node so it's not buggy and has some actual good advice.