ybiC has asked for the wisdom of the Perl Monks concerning the following question:
&CONFEXT is supposed to populate $timeout, @targets, and @command from the file ciscoconf.conf. As the Dumps show, CONFINT isn't fetching all the info into the appropriate arrays. I think my "push" syntax is good, and suspect my control structure is *not*. Would any wise monk(s) care to show me the error of my ways?
Hopefully relevant sections of code follow:
tired groggy and quite loopy,
Don
striving for Perl Adept
(it's pronounced "why-bick")
###################################################################### +### # Begin small slice of ciscoconf.pl use Data::Dumper; #only for testing use vars qw( $section $timeout @timeout $target @targets $command @commands ); my $conf = 'ciscoconf.conf'; # list of target devices and +commands my $tmp = 'ciscoconf.tmp'; my $log = 'ciscoconf.log'; #&CONFINT(); &CONFEXT(); ---------------------------------------------------------------------- +--- sub CONFINT { $timeout = '15'; @targets = ('192.168.1.27','172.16.0.138' ); @commands = ( 'sho clo', 'set leng 0', 'term leng 0', 'sho clo', 'disa', ); open (DUMP, "> ciscoconfint.dump") or die "Error opening ciscocon +fint.dump for write: $!"; print DUMP Dumper(@timeout), "\n"; print DUMP Dumper(@targets), "\n"; print DUMP Dumper(@commands), "\n"; close (DUMP) or die "Error closing ciscoconfint.dump after write: + $!"; } ---------------------------------------------------------------------- +--- sub CONFEXT { open (CONF, "<$conf") or die "Error opening $conf for read: $!"; while (<CONF>) { next if /^#/ or /^s.*$/ or /^!/; # ignore comment lines chomp; if (/^\[([^\]]+)\]/) { $section = $1; next; } else { if ($section =~ /timeout/i) { push @timeout,$_; } if ($section =~ /targets/i) { push @targets,$_; } if ($section =~ /commands/i) { push @commands,$_; } } } close (CONF) or die " ciscoconf.pl: Error closing $conf after re +ad: $!"; open (DUMP, "> ciscoconfext.dump") or die "Error opening ciscocon +fext.dump for write: $!"; print DUMP Dumper(@timeout), "\n"; print DUMP Dumper(@targets), "\n"; print DUMP Dumper(@commands), "\n"; close (DUMP) or die "Error closing ciscoconfext.dump after write: + $!"; } # End small slice of ciscoconf.pl ###################################################################### +### # begin ciscoconf.conf [Timeout] 15 [Targets] 192.168.1.27 172.16.0.138 [Commands] sho clo set leng 0 term leng 0 disa sho clo # end ciscoconf.conf ###################################################################### +### # begin ciscoconfext.dump $VAR1 = 15; $VAR2 = ''; $VAR1 = '192.168.1.27'; $VAR2 = '172.16.0.138'; $VAR3 = ''; $VAR1 = 'term leng 0'; $VAR2 = 'disa'; # end ciscoconfext.dump ###################################################################### +### # begin ciscoconfint.dump $VAR1 = 15; $VAR1 = '192.168.1.27'; $VAR2 = '172.16.0.138'; $VAR1 = 'sho clo'; $VAR2 = 'set leng 0'; $VAR3 = 'term leng 0'; $VAR4 = 'sho clo'; $VAR5 = 'disa'; # end ciscoconfint.dump ###################################################################### +###
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing external config file
by mirod (Canon) on Jan 21, 2001 at 14:57 UTC | |
by ybiC (Prior) on Jan 21, 2001 at 15:39 UTC | |
|
Re: Parsing external config file
by BoredByPolitics (Scribe) on Jan 21, 2001 at 18:17 UTC | |
by ybiC (Prior) on Jan 21, 2001 at 19:34 UTC | |
by BoredByPolitics (Scribe) on Jan 21, 2001 at 20:22 UTC |