Limo has asked for the wisdom of the Perl Monks concerning the following question:

So, now I've changed things alittle, and re-defined my format.

  system {
       host steve-1;
       domain-search  myhost.com myhost.net;
       time/zone Here/There;
       auth-order  my password;
       root-auth {
  #          enc-pwd "NOWAY"; #YOU CANT HAVE THIS
       }

  server {
       1.2.3.4;
       5.6.7.8;
  }

should look like:


system host steve-1;
system domain-search  myhost.com myhost.net;
system time/zone Here/There;
system auth-order my password;    
       
.......blah, blah,blah    

here's what I've got: }

while (<>); {

if (/^system/) {
   @prepend = "system";

Now, what I'm trying to do is read between "{" and "}", prepend "system" and whitespace to each line. That is a rule that will apply to the entire config file. Anyone care to help a newbie out?

Replies are listed 'Best First'.
Re: Follow up to:
by merlyn (Sage) on Aug 24, 2000 at 23:59 UTC
    Perhaps something like this:
    my @prefix; while (<>) { next if /^#/; # skip comments, apparently if (/^\s*(\S+)\s*\{\s*$/) { push @prefix, $1; } elsif (/^\s*\}\s*$/) { pop @prefix; # no error checking } elsif (/^\s*(.*)/) { print "@prefix " if @prefix; print $1, "\n"; } else { die "internal error on $_"; } }

    -- Randal L. Schwartz, Perl hacker