Yes I read readdir, I'm assuming "file testing the return values out of a readdir" is my case of why I can't use it?
Yes, that part, if you're reading from "Foo/" getting a file of "Bar" and then you try to open "Bar" its not going to work as you need to open "Foo/Bar"
used glob like you said. No more errors, but I get no output to STDOUT. I placed "print "$file\n" at the end of my first for loop and I see the files are being iterated through, but the guts of the script where I'm trying to find names and object-groups is not showing any output.
This is where subroutines play important part. Consider this version
usr/bin/perl -- ## 2015-09-21-18:21:28 ## ## ## ## ## ## perltidy -olq -csc -csci=3 -cscl="sub : BEGIN END " -otr -opr -ce +-nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if " -otr -opr +-ce -nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while " -otr + -opr -ce -nibc -i=4 -pt=0 "-nsak=*" ## perltidy -olq -csc -csci=10 -cscl="sub : BEGIN END if while for " +-otr -opr -ce -nibc -i=4 -pt=0 "-nsak=*" #!/usr/bin/perl -- use strict; use warnings; use Path::Tiny qw/ path /; Main( @ARGV ); exit( 0 ); sub Main { my @files = path( "Configs/" )->children; for my $file ( @files ) { FaFyle( $file ); } } ## end sub Main sub FaFyle { my( $file ) = @_; my $config = ReadConfig( $file ); NaNameConfMod( $config ); ObObjectsConfMod( $config ); } ## end sub FaFyle sub ReadConfig { return [ path( $_[0] )->lines_raw( { chomp => 1 } ) ]; } ## end sub ReadConfig sub NaNamesConfMod { my( $configref ) = @_; my @names = map { /^name \d+\.\d+\.\d+\.\d+ ([A-Za-z0-9-_]+)$/ ? $ +1 : () } @{$configref}; @{$configref} = grep { $_ !~ /^name / } @{$configref}; FaFindCb( sub { print "name $_[0] unused\n" }, \@names, $configref + ); return; } ## end sub NaNamesConfMod sub ObObjectsConfMod { my( $configref ) = @_; my @objects = map { /^(object|object-group) (network|service) ([A-Za-z0-9-_]+)$/ ? $3 : () } @{$configref}; @{$configref} = grep { $_ !~ /^(object|object-group) / } @{$config +ref}; FaFindCb( sub { print "object $_[0] unused\n" }, \@objects, $confi +gref ); return; } ## end sub ObObjectsConfMod sub FaFind { my( $callback, $objects, $config ) = @_; foreach my $object ( @$objects ) { if( !grep { $_ =~ /\Q$object\E/ } @{$config} ) { $callback->( $object ); } } } ## end sub FaFind __END__ __END__
If NaNamesConfMod() isn't working, there is no need to try to debug all the other parts, just NaNamesConfMod( [ "test data" ] ); sub NaNamesConfMod{... }
In reply to Re^5: Trouble opening and reading file within loop (readdir)
by Anonymous Monk
in thread Trouble opening and reading file within loop
by H0tc@xe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |