Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Parsing and editing a configuration file

by shmem (Chancellor)
on Jun 23, 2019 at 15:04 UTC ( [id://11101764]=note: print w/replies, xml ) Need Help??


in reply to Parsing and editing a configuration file

I'd just be lazy and use a flip-flop.

#!/usr/bin/perl -n if(/RECORD\s+"(?:ABC|XYZ)"/ ... /END_VIEW/) { s/^\s*field\s+\K"region"/"LOCATION"/i; s/^\s*field\s+\K"rubbish"/"TRASH"/i; } print;

Having the structure inline, I'd just split then into @lines and say for(@lines) { ... }

More matching pairs can be introduced with nested if-blocks of the same form - if (m{...} ... m{...}) { ... }

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Log In?
Username:
Password:

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

    No recent polls found