Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^3: Contextual find and replace large config file

by LanX (Saint)
on Jan 03, 2019 at 14:49 UTC ( [id://1227986]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Contextual find and replace large config file
in thread Contextual find and replace large config file

> (separate parsing...semantic logic). What do you mean with that? 

Your two examples seem to hold the same information (semantic) while having different format (syntax).

So better write parsers for the different formats which "cache" them in an intermediate format. These parsers should be ignorant about the meaning just concentrating on correctness.

The semantics - the meaning of the data - could be handled by one central module which only operates on the intermediate format. This module could be reused for all formats.

A possible intermediate format could be nested hashes

$cache = { ObjectType1 => { Param1 => 8, Param2 => "SomeText", NestedObject => { Param1 => 3, Param2 => "SomeText" } }

Of course this highly depends on the nature of your data, like

  • does order matter?
  • are repeated elements allowed?
Using nested arrays may be better then°

And after transforming your data you can also have emitter modules to write them into a new out file.

Like this you are even capable to transform between different formats, or add new ones.

HTH! :)

edit

NB: this approach is also useful when handling only one input format, because you can cleanly separate code, hence much better maintain it.

update

°) or a mix of hashes and arrays. Or even using Perl objects blessing elements into different "ObjectTypes", ...

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-19 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found