Is there any way to call a function w/in an RE

E

El Duce

I would like to call a function w/in an RE. Say foo:

$x =~ s/abc(.*)def/foo($1)/g;

(I know that syntax doesn't work, but you hopefully get the idea).

Is there a way?

TIA,
El Duce
 
A

Anno Siegel

El Duce said:
I would like to call a function w/in an RE. Say foo:

$x =~ s/abc(.*)def/foo($1)/g;

(I know that syntax doesn't work, but you hopefully get the idea).

Is there a way?

Look for the /e modifier in perlop.
TIA,
El Duce

Hmmm?

Anno
 
B

Brian McCauley

El said:
I would like to call a function w/in an RE. Say foo:

$x =~ s/abc(.*)def/foo($1)/g;

The LHS of a s/// is a regex, the RHS (without a /e switch) is just a
double-quotish string.

The question "How do I expand function calls in a string?" is a FAQ.

However the /e switch makes the RHS of s/// be parsed as a plain Perl
expression.

Had you really wanted to call a function inside a regex there (which you
didn't but others finding this thread on a search engine might) you can
use the (?{}) or (??{}) syntax documented in perlre.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,430
Latest member
7dog123

Latest Threads

Top