Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: How to write at immediate next line of detecting a particular pattern

by Random_Walk (Prior)
on Jan 26, 2014 at 10:29 UTC ( [id://1072122]=note: print w/replies, xml ) Need Help??


in reply to How to write at immediate next line of detecting a particular pattern

You will read your file line at a time, and write the results to a new file. When you hit your pattern in the input stream, write your 200+line variable. Once this is done you can contiue reading and adding the rest of the original file, either line at a time, or by undefining the input field seperator: $/, as one block. Finally copy the new output file over the original

As the tag <TARGET> looks rather like an XML or HTML like thing, perhaps you should look at proper *ML parsers, to acheive your aim more reliably

When you have some code do post it, and we will be glad to help further

# pseudo code that will not run unless you do some homework... use strict; use warnings; my $big_var = "Some massive\nstring\n"; # that big 200 line var goes h +ere my $pattern = "<TARGET>"; open my $input input file open my $output output file while read line from input { print to output if pattern is matched { print $output $big_var } } close both files copy output over input

PS What will happen if TARGET tag is not on the end of a line?

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-19 08:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found