Hi,
I have been trying to call Perl code from inside the replace part of a regular expression using the
(?{CODE}) construct. My script is as follows:
$str = "(<ref links=\" cit314-1 cit314-2 cit314-3 cit314-4 cit314-5\"/
+>)";
if( $str =~ s/<ref links=\"(.*?)\"(.*?)\/>/<ref links=\"$1\"$2>(?{ pri
+nt $1 })<\/ref>/ ){
print "Match was found." . "\n";
}
print $str . "\n";
The output I get is:
Match was found.
(<ref links=" cit314-1 cit314-2 cit314-3 cit314-4 cit314-5">(?{ print
+ cit314-1 cit314-2 cit314-3 cit314-4 cit314-5 })</ref>)
Notice that the "print" command was not executed while the
$1 was replaced with its value. I would appreciate all help/ideas.
Thanks,
Christos
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.