in reply to regex (?{CODE}) question
The print command isn't executed because it's not in the regex. The first portion of the s/// (between the first two //'s) is a regex; the other portion could be considered a string. So you need to place the (?{ print $1 }) at the end of the regex part, like so:
Notice I also didn't escape the quotes -- this isn't necessary and, I think, it makes things look a little messier.$str = "(<ref links=\" cit314-1 cit314-2 cit314-3 cit314-4 cit314-5\"/ +>)"; if( $str =~ s/<ref links="(.*?)"(.*?)\/>(?{ print $1, "\n" })/<ref lin +ks="$1"$2><\/ref>/ ){ print "Match was found." . "\n"; } print $str . "\n";
elusion : http://matt.diephouse.com
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: regex (?{CODE}) question
by Ferret (Scribe) on Aug 01, 2002 at 19:34 UTC | |
by elusion (Curate) on Aug 01, 2002 at 19:37 UTC | |
by ctgIT (Initiate) on Aug 01, 2002 at 19:53 UTC | |
by elusion (Curate) on Aug 01, 2002 at 19:59 UTC |
In Section
Seekers of Perl Wisdom