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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Need a Custom or Prewritten Perl Program?: I need a program that...:
Search and Add Help


New User

Mar 24, 2006, 12:25 PM

Post #1 of 1 (1376 views)
Search and Add Help Can't Post

I have a large file that I need to add additional lines into. I need to be able to search through a file for this pattern:

DEFINITION "mydefinition"

and then add something like the following after the curly brace:

PROPERTY "Permitted to Write"
{Edit Text Length 4074 DEFAULT "dear_admin"}

So... I end up with

DEFINITION "mydefinition"

PROPERTY "Permitted to Write"
{Edit Text Length 4074 DEFAULT "dear_admin"}

The DEFINITION is preceeded by a newline and the curly brace is almost always on the following line. What is in the quotes will be different for every DEFINITION instance. There are several hundered of these I need to change and it seems the Perl is the correct way to go.

A single line file reader won't work since the search string is on multiple lines. So, something like

if ( $_=~ /\nDEFINITION ".+"\n{/)

which is probably incorrect, won't work.

Scripts that I have looked at are searching for a string and replacing. This is somewhat akin but I think the algorithm is more likely:

Find the string <newline>"DEFINITION"
Find the second instance of " character

Find the curly brace

Insert Text

End find curly brace

End find "


Guru help is greatly appreciated.


(This post was edited by m00t on Mar 27, 2006, 10:07 AM)


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

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