Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Drop in regex replacements?

by Ovid (Cardinal)
on Sep 09, 2002 at 15:02 UTC ( [id://196293]=note: print w/replies, xml ) Need Help??


in reply to Drop in regex replacements?

One relatively simple way to accomplish this would be to use subrefs with the 'e' switch (though I'd still use a parser instead):

#!/usr/bin/perl -w use strict; my $foo = sub { "$1 years ago" }; my $bar = 'Four score and perhaps seven'; $bar =~ s/perhaps (seven)/&$foo/e; print $bar;

Cheers,
Ovid

Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

Replies are listed 'Best First'.
Re: Re: Drop in regex replacements?
by IOrdy (Friar) on Sep 09, 2002 at 16:41 UTC
    Thanks Ovid that makes more sense.

    My origional code was in php and that did support adding the replace part of the regex as a string from somewhere else (i.e. a hash). I was thinking if preg_replace() can do it why can't a real perl replace regex do it :-)

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2024-04-26 04:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found