Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Re: Re: regex (?{CODE}) question

by elusion (Curate)
on Aug 01, 2002 at 19:37 UTC ( #186904=note: print w/replies, xml ) Need Help??

in reply to Re: Re: regex (?{CODE}) question
in thread regex (?{CODE}) question

While in a code block, $1 is correct. This is necessary because it's executed as actual code. I'm not sure how \1 would actually parse, though I assume it'd be a reference to 1.

elusion :

Replies are listed 'Best First'.
Re: Re: Re: Re: regex (?{CODE}) question
by ctgIT (Initiate) on Aug 01, 2002 at 19:53 UTC
    Thanks for your reply. Actually, my objective is not to print $1 but to call a subroutine from inside the replace part of the regex which will use the value of $1 to produce a string that will be used in the replace part. For example, something like:
    $str = "(<citationref linkend=\" cit314-1 cit314-2 cit314-3 cit314-4 c +it314-5\"/>)"; if( $str =~ s/<ref links=\"(.*?)\"(.*?)\/>/<ref links=\"$1\"$2>(?{ &ge +tString($1) })<\/ref>/ ){ print "Match was found." . "\n"; } print $str . "\n"; sub getString($s){ my $s = shift; ...more processing of $s... return $s; }
      Try using the /e modifier. What it does is make the second half of the regex executed as code. In your case you'd want something like this:
      $str = "(<ref links=\" cit314-1 cit314-2 cit314-3 cit314-4 cit314-5\"/ +>)"; if( $str =~ s/<ref links="(.*?)"(.*?)\/>/ "<ref links=\"$1\"$2>" . getString($1) . "<\/ref>"/e ){ print "Match was found." . "\n"; } print $str . "\n"; sub getString($s){ my $s = shift; ...more processing of $s... return $s; }
      Your $str changed from your previous posts, so I changed it back to the way it was in the other posts. Notice how I quoted the tags and concatenated them with the return value from the subroutine. I also did some extra formatting. Hope this helps.

      elusion :

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2020-01-19 21:06 GMT
Find Nodes?
    Voting Booth?