CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Substitute in a subparagraph

 



guyov2
Novice

Oct 17, 2008, 10:36 AM

Post #1 of 10 (922 views)
Substitute in a subparagraph Can't Post

Hello,
I'm trying to write a script which searches a file that contains a lot of paragraphs.
At first I need to check the paragraph's headline and if it matches I need to substitute a string in that specific paragraph only.

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 need to do that "double search" a lot of times, for matching more than just one paragraph.

Thanks a lot,
Guy

Code



      
    


KevinR
Veteran


Oct 17, 2008, 12:18 PM

Post #2 of 10 (920 views)
Re: [guyov2] Substitute in a subparagraph [In reply to] Can't Post

Post some sample data and what you want to accomplish with the sample data. Suggestions will depend on the data.
-------------------------------------------------


guyov2
Novice

Oct 18, 2008, 1:42 AM

Post #3 of 10 (916 views)
Re: [KevinR] Substitute in a subparagraph [In reply to] Can't Post

 
Ok, so lets say this is part of the text I'm looking at :


285 blabla_data[28] OUTPUT (
286 REQUIRED (
287 lead_up 0.193118 br fclk clkdom(3)
288 early_lea clkdom(3)
289 late_trail_dn -0.084738 br fclk clkdom(3)
290 late_tra
291 )
292 cext %0.00151055
299 min_ceff_up %0.034
300 TEXT TO BE REMOVED
301 )
302 blabla2 [145] OUTPUT (
303 REQUIRED (
304 early qclk clkdom(6)
305 early_l qclk clkdom(7)
306 late_trail_dn -0.125163 bf qclk clkdom(7)
307 late_t(7)
308 TEXT TO BE REMOVED
309 )


As you see there are a lot of paragraphs in it containing headlines called "blabla", I want to delete all the "TEXT TO BE REMOVED" except for the paragraphs called "blabla2" .

I need these replacements to happen all along the file.

Thanks a lot,
Guy


KevinR
Veteran


Oct 18, 2008, 11:01 AM

Post #4 of 10 (909 views)
Re: [guyov2] Substitute in a subparagraph [In reply to] Can't Post

When you said titles and paragraphs I expected to see something very different:


Code
Some Title 

A paragraph of descriptive text that
has them rolling in the aisles.

Another Title

Another illuminating paragraph of
text that leaves them wanting more.


Instead you have posted some type of a file. Is this file some type of a standard file? Is there possibly already a module that knows how to parse this file? Have you written any code yet to try and accomplish your requirement(s)?
-------------------------------------------------


guyov2
Novice

Oct 18, 2008, 11:40 AM

Post #5 of 10 (908 views)
Re: [KevinR] Substitute in a subparagraph [In reply to] Can't Post

There is no module.
I have just written a code that matches lines including "blabla2" but that's it.

I just need to understand how to start a "subsearch" when finding my target string. Because I know that after that line number will follow "TEXT TO BE REMOVED".
Is there a way to start s/// from a specific line?


KevinR
Veteran


Oct 18, 2008, 12:57 PM

Post #6 of 10 (905 views)
Re: [guyov2] Substitute in a subparagraph [In reply to] Can't Post

Are you literally looking for "TEXT TO BE REMOVED" or is that dummy data?
-------------------------------------------------


guyov2
Novice

Oct 18, 2008, 1:34 PM

Post #7 of 10 (904 views)
Re: [KevinR] Substitute in a subparagraph [In reply to] Can't Post

dummy, the real one is QUALI_CH .


KevinR
Veteran


Oct 18, 2008, 1:43 PM

Post #8 of 10 (903 views)
Re: [guyov2] Substitute in a subparagraph [In reply to] Can't Post

Are the line number also in the data like you posted? Is it possible to post some real data? Attach the data to a post instead of putting the data in the post.
-------------------------------------------------


guyov2
Novice

Oct 18, 2008, 2:09 PM

Post #9 of 10 (899 views)
Re: [KevinR] Substitute in a subparagraph [In reply to] Can't Post

The lines are in the data.
I'm not allowed to publish that data.
But the file looks exactly the way I put it here.


KevinR
Veteran


Oct 18, 2008, 2:51 PM

Post #10 of 10 (895 views)
Re: [guyov2] Substitute in a subparagraph [In reply to] Can't Post

So far I am not having much luck parsing that file. I will try later today or maybe someone else will come along and have a suggestion or two. You may want to try www.perlmonks.com also.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives