Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Approach to remove brackets from config

by samtregar (Abbot)
on Aug 20, 2008 at 17:52 UTC ( [id://705571]=note: print w/replies, xml ) Need Help??


in reply to Approach to remove brackets from config

I would code it in two steps. First, write a parser which parses your (bizarre) config format into a Perl data structure. For you example you might attempt to produce something like:

my %data = ( server => { "hostname" => "test". "console-type" => { "type" => "vt100", }, "account root" => { "authentication-type" => { "password" => q{"bubba"} } } );

Second, write some Perl code that takes your parsed data-structure and outputs the CLI commands. Neither step is completely trivial, but they shouldn't be too hard for a competent programmer. If it were my job I think I'd do the first step with Parse::RecDescent, but if you've never used it before it's probably more trouble than it's worth. Give it a try and post again if you run into trouble.

-sam

Replies are listed 'Best First'.
Re^2: Approach to remove brackets from config
by psini (Deacon) on Aug 20, 2008 at 21:32 UTC

    If the syntax of the config file is fully represented in the example, a single regex substitution on each line could be enough. Something like:

    s/^\s*([\w-])\s*/"$1" => /

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

      That doesn't work. It's not too far off, but I think a real parser will be easier to write and more reliable.

      -sam

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-25 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found