H0tc@xe has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w # use warnings; use strict; opendir(DH, "Configs/"); my @files = readdir(DH); closedir(DH); foreach my $file (@files) { # Read config from .txt files in Dir. open my $fh, "<", $file or die "Can't open '$file': $!"; my @config = <$fh>; close $fh; chomp @config; my $configref = \@config; # Extract names from config. my @names = map { /^name \d+\.\d+\.\d+\.\d+ ([A-Za-z0- +9-_]+)$/ ? $1 : () } @{ $configref }; # Remove names from config. @config = grep { $_ !~ /^name / } @config; # Find unused name references. foreach my $name (@names) { if (!grep { $_ =~ /$name/ } @config) { print "name $name unused.\n"; } } # Extract objects from config. my @objects = map { /^(object|object-group) (network|s +ervice) ([A-Za-z0-9-_]+)$/ ? $3 : () } @{ $configref }; # Remove objects from config. @config = grep { $_ !~ /^(object|object-group) / } @co +nfig; # Find unused object references. foreach my $object (@objects) { if (!grep { $_ =~ /$object/ } @config) { print "object $object unused.\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Trouble opening and reading file within loop (readdir)
by Anonymous Monk on Sep 21, 2015 at 22:23 UTC | |
by Anonymous Monk on Sep 21, 2015 at 22:24 UTC | |
by H0tc@xe (Initiate) on Sep 22, 2015 at 00:50 UTC | |
by Anonymous Monk on Sep 22, 2015 at 00:59 UTC | |
by H0tc@xe (Initiate) on Sep 22, 2015 at 01:32 UTC | |
by Anonymous Monk on Sep 22, 2015 at 01:49 UTC | |
|
Re: Trouble opening and reading file within loop
by GotToBTru (Prior) on Sep 22, 2015 at 13:05 UTC | |
|
Re: Trouble opening and reading file within loop
by tangent (Parson) on Sep 22, 2015 at 13:00 UTC |