Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Substitute in a subparagraph

by blazar (Canon)
on Oct 19, 2008 at 10:47 UTC ( [id://718041]=note: print w/replies, xml ) Need Help??


in reply to Substitute in a subparagraph

I know how to use m//g for search and s/// for substituting but I don't know how to to a "double search": after finding my match - finding another match inside.

I personally believe that -letting your actual problem aside for a moment- as soon as you know how to write a sub, you should have solved your problem: you should know that the /e modifier allows you to include code in the substitution part of an s///. So just capture the text you want to process, and process it in a separate sub. Of course, you can also inline the sub code in the substitution part itself. But then you will have to pay much care to the delimiters, or else the perl parser may easily get confused. For example, the whole program I suggested elsewhere may be cast into the form of a single substitution:

s/ ^ \b ( [ \w \s \[ \] ]+ \s+ \( ) $ ( .*? ^\)$ ) / my ($head, $body)=($1, $2); $body =~ s|QUALIFIED|| unless $head ~~ m|^\w+?clk\[\d\]|; $head . $body /gemsx;
--
If you can't understand the incipit, then please check the IPB Campaign.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2024-04-23 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found