Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Is it possible to use perl subroutines inside regexp, using backreferences as parameters? Something like this
I want to get 'Hello la-la-la' in $str, by get Hello &test(world).sub test{ my $value=shift; print $value; return 'la-la-la' ; } my $str = 'Hello _world_'; $str =~ s/_(.*?)_/&test(\1)/g;
May be I've got XY problem? I want to use in templates in my web-framework something like
So, the output of SomeModule should be substituted in template. So, if I want to write something like s/{_(.*?)_}/&call_module(\1)/g Thanks, Alex..... <body> ... {_SomeModule_} </body> ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Call subroutines inside regexp, using backrefences as parameters
by moritz (Cardinal) on Mar 31, 2010 at 12:42 UTC | |
by Anonymous Monk on Mar 31, 2010 at 12:46 UTC | |
|
Re: Call subroutines inside regexp, using backrefences as parameters
by JavaFan (Canon) on Mar 31, 2010 at 14:37 UTC |