Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Re: Re: Applying a RegEx in a variable

by ChOas (Curate)
on Aug 10, 2001 at 16:22 UTC ( #103846=note: print w/replies, xml ) Need Help??

in reply to Re: Re: Applying a RegEx in a variable
in thread Applying a RegEx in a variable

let`s keep dangerous content of the eval out of this...

I want to eval the expression whilst retaining information on the special
RegEx vars ($1..n, $&,$`,$', etc, etc) It really SHOULD be possible

I`m actually very close to printing the regex to a file, run the file as a Perl
program, let it print the vars to another file, and read them back into the
parent.... Now that`s what I call desperation....


print "profeth still\n" if /bird|devil/;
  • Comment on Re: Re: Re: Applying a RegEx in a variable

Replies are listed 'Best First'.
Re4: Applying a RegEx in a variable
by Hofmator (Curate) on Aug 10, 2001 at 16:37 UTC

    Well, you can always do it the qr// way (this is better anyway if you are using the same regex more than once). Or you can do it along these lines:

    my $match; eval "\$String =~ $RegEx"; \$match = \$&"; print $match;
    The code executed within the eval has access to the variables outside - again it works the same way as if the evaluated code was in a code block of its own.

    -- Hofmator

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://103846]
[erix]: (NSFC - Not Safe For Church)

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2017-09-24 20:32 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (274 votes). Check out past polls.