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