in reply to Read in a regex without having to use string eval?
qr{(?<NASPRE>\QNAS-IP-Address=\E)}
is not a regex pattern. It's a Perl operator, it's Perl code. You need eval EXPR or similar to execute Perl code.
Now, if you actually had a regexp pattern, say
(?-xism:(?<NASPRE>NAS\-IP\-Address\=))
there wouldn't be need for eval EXPR or similar.
orchomp( my $pat = <DATA> ); while (<DATA>) { print if /$pat/; } __DATA__ (?-xism:(?<NASPRE>NAS\-IP\-Address\=)) ...
chomp( my $pat = <DATA> ); my $re = qr/$pat/; while (<DATA>) { print if /$re/; } __DATA__ (?-xism:(?<NASPRE>NAS\-IP\-Address\=)) ...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Read in a regex without having to use string eval?
by Argel (Prior) on Nov 23, 2011 at 01:21 UTC | |
by ikegami (Patriarch) on Nov 23, 2011 at 01:32 UTC | |
by Argel (Prior) on Nov 23, 2011 at 02:17 UTC |
In Section
Seekers of Perl Wisdom