use strict; use warnings; my %seen = (); my $flag = 0; my (@nonprod_lpars, @lparstat, $clntdir); my $regexp_2_skip = qr/entitled capacity of pool/i; my $regexp_2_get = qr/entitled capacity|desired Virtual CPU|desired Memory|online Virtual CPU|maximum Virtual CPU|maximum memory|online memory/i; my $datacsv = qq($basedir/nonprod_resource_stats_4_mgmt.csv); open (my $csv, ">>$datacsv") or die "failed to open $datacsv $!\n"; sub _ce { print "IN CE SUB\n"; die "no parameter!\n" unless @_; my ($ce_ref) = @_; for my $name (@{ $ce_ref }) { @asof = +(split("/", $name, 0))[-3,-2,-4]; $lpname = +(split("/", $name, 0))[3]; print $csv "$lpname\n"; print $csv '*' x length($lpname),"\n"; print '*' x length($lpname),"\n"; print "$name\n"; open (my $i, "+<", $name) or warn $!; ### FAILS HERE ### while (<$i>) { chomp $i; next if $i =~ /$regexp_2_skip/; next if $i !~ /$regexp_2_get/; ($i) =~ s/:/,/g; ($i) =~ s/\s+//g; print $csv "$i,\n"; print "$i,\n"; } } print $csv "\n\nHost,Entitled CPU and RAM as of @asof,\n\n"; return; } ... ... print "heading into lparstat find $clntdir count of nonprodlpars", scalar @nonprod_lpars; for my $npll (@nonprod_lpars) { next if $npll =~ /null/i; print "\nnpll: $npll"; push @lparstat, qx(/usr/bin/find "$clntdir/$npll" -name $lparstout -mtime 1); print " lparstat count:", scalar @lparstat; } if ( scalar @nonprod_lpars == scalar @lparstat ) { $flag = 1; print "\nFLAG:$flag\n"; _ce( \@lparstat ); } else { print "at top of mtime 2 block\n"; print "SCALAR NPLPARS ",scalar @nonprod_lpars; for my $npll (@nonprod_lpars) { next if $npll =~ /null/i; push @lparstat, qx(/usr/bin/find "$clntdir/$npll" -name $lparstout -mtime 2); } print "SCALAR lparstat: ", scalar @lparstat; if ( scalar @nonprod_lpars == scalar @lparstat ) { $flag = 2; _ce( \@lparstat ); } . . . __OUT__ $name is clearly getting passed ok from my prints: No such file or directory at get_nonprod_AIX_resrcs_used.plx line 456. readline() on closed filehandle $i at get_nonprod_AIX_resrcs_used.plx line 457. ************ /opt/r2configs/twcsapcont01/2018/03/13/lparstat-i.out and a confirmation it does exist is here # ls -l /opt/r2configs/twcsapcont01/2018/03/13/lparstat-i.out -rw-r--r-- 1 root system 2225 Mar 13 21:16 /opt/r2configs/twcsapcont01/2018/03/13/lparstat-i.out