Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Replacing a block of text inside two keys with another block of text

by GrandFather (Saint)
on Apr 24, 2017 at 21:32 UTC ( [id://1188800]=note: print w/replies, xml ) Need Help??


in reply to Replacing a block of text inside two keys with another block of text

What does your input data look like? Show us a sample of the file you are processing. How confident are you that the structure of the "hash" you are editing won't change? If the file is written by Perl there is a fair chance that you can't depend on the order of the elements.

Perhaps the more important question: what is the problem you are trying to solve? It is likely there is a better solution than a poor man's parse and edit of a text representation of a data structure.

Premature optimization is the root of all job security
  • Comment on Re: Replacing a block of text inside two keys with another block of text

Replies are listed 'Best First'.
Re^2: Replacing a block of text inside two keys with another block of text
by victorz22 (Sexton) on Apr 24, 2017 at 22:03 UTC

    I'm not sure how to modify the file since I am unable to load the file in and access the hash. If there is another solution I will be more than happy to implement it.

    #what replacement data looks like "new/path/desired/data" "new/path/desired/data" "new/path/desired/data"
    #data looks kinda like this key1 => { #some data i don't need #more data i don't need <<'END_SEARCHPATHS', #block of data I want to replace "some/path/to/some/file" "some/path/to/some/file" "some/path/to/some/file" "some/path/to/some/file" "some/path/to/some/file" "some/path/to/some/file" END_SEARCH_PATHS } key2 => { <<'END_SEARCHPATHS', #another block of data to replace "another/path/to/some/file" "another/path/to/some/file" "another/path/to/some/file" "another/path/to/some/file" END_SEARCH_PATHS }
      Filtering a dumped hash like this will not work reliably.

      Read the file in with do and filter the desired hash keys with a grep

      if this is not possible because of size or because order matters (i.e. wrong data format) consider using another data format!

      Probably best a SQL DB

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)
      Je suis Charlie!

      Your "sample data" sometimes omits the underscore in SEARCH_PATHS. If your real data does that, maybe that's one of your problems? If it doesn't, please stop giving us sample data that isn't representative.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1188800]
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: (4)
As of 2024-04-24 11:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found