Beefy Boxes and Bandwidth Generously Provided by pair Networks httptech
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Read in a regex without having to use string eval?

by ikegami (Pope)
on Nov 23, 2011 at 01:13 UTC ( #939571=note: print w/ replies, xml ) Need Help??


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.

chomp( my $pat = <DATA> ); while (<DATA>) { print if /$pat/; } __DATA__ (?-xism:(?<NASPRE>NAS\-IP\-Address\=)) ...
or
chomp( my $pat = <DATA> ); my $re = qr/$pat/; while (<DATA>) { print if /$re/; } __DATA__ (?-xism:(?<NASPRE>NAS\-IP\-Address\=)) ...


Comment on Re: Read in a regex without having to use string eval?
Select or Download Code
Re^2: Read in a regex without having to use string eval?
by Argel (Prior) on Nov 23, 2011 at 01:21 UTC
    I knew I was missing something obvious! I'm so used to using quotemeta in RegEx's that I was thinking it was RegEx code, not Perl code! Thanks! Needed someone to point that out to me!! I'm aware about the rest.

    Elda Taluta; Sarks Sark; Ark Arks
    My deviantART gallery

      I was actually referring to the qr{} part, but yeah, it's basically the same for \Q.

      The deal with the quotemeta escape and such as well as interpolation is that they are meaningful in literals (such as qq"" and qr//), but they are not perceived as such by the regex engine should they be provided to it.

      You can print out the result of qr to see the pattern that got compiled.

        I figured you meant the qr{}, but that along with the fact you did not use the quotemeta tags in any example was enough to jolt my brain into remembering that quotemeta was also Perl code. It's amazing how simple mistakes can be so hard to catch at times!! Again, thanks for the help!!

        Elda Taluta; Sarks Sark; Ark Arks
        My deviantART gallery

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://939571]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-04-21 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (490 votes), past polls