I'm creating a process which will regenerate a configuration file each time it is run. If a certain variable is found in the original config file, I want to avoid clobbering the entry while I'm regenerating the config file.Here's what the config file looks like:
<users> <00149> <devsrv1> lastLogin Never logged in approvedBy SLS </devsrv1> <devsrv2> lastLogin Never logged in </devsrv2> </00149> </users>
This would be what the original config file would look like. Let's say I'm ready to regenerate the config file. While parsing throught the above, I want to ignore all records which contain the variable, "approvedBy", when I'm regenerating the config file.

Here's the code that I've got, so far:

## assume that I'm using strict, using warnings, and that all data str +uctures tus far, are populated correctly. I'm truncating the code for + the sake of brevity foreach my $inner (keys %{$users{$lastuid}}) { my $last = $users{$lastuid}{$inner}; genCtl($inner, $last, $lastuid); } print FH "\t\<\/m$newuid\>\n"; } print FH "\<\/users\>\n"; $conn->close; close FH; my $conf = new Config::General( -ConfigPath => \@path, -ConfigFile => "$ctlFile", -ExtendedAccess => 1, -InterPolateVars => 1 ); my %config = $conf->getall(); $conf->save_file("$tmpctlFile"); &procCtl; sub genCtl { my ($server, $last, $uid) = @_; print FH "\t\<$server\>\n"; print FH "\t\tlastLogin $last\n"; print FH "\t\<\/$server\>\n"; print FH "\t\tlastLogin $last\n"; print FH "\t\<\/$server\>\n"; } sub procCtl { my $tmpCtl = new Config::General( -ConfigPath => \@path, -ConfigFile => "$tmpctlFile", -ExtendedAccess => 1, -InterPolateVars => 1 ); my %tmpCtl = $tmpCtl->getall(); my $goldCtl = new Config::General( -ConfigPath => \@path, -ConfigFile => "$goldCtlFile", -ExtendedAccess => 1, -InterPolateVars => 1 ); my %goldCtl = $tmpCtl->getall(); my $tmpUser = $tmpCtl->obj("users"); my $goldUser = $goldCtl->obj("users"); foreach my $person ($tmpUser->keys("users")) { foreach my $server ($tmpUser->keys("$person")->obj("server")) { { my $approved = $tmpCtl->obj("approvedBy"); next if ($approved); } } $tmpCtl->save_file("$goldCtlFile"); } }

In reply to Comparing two config files using Config::General by blink

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.