in reply to opening a file passed into sub as ref
The code you show can't be the code you're running.
A reduced version of your code dies with an error for me:
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 M +emory|online Virtual CPU|maximum Virtual CPU|maximum memory|online me +mory/i; my @asof; 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,\n\n"; return; } @lparstat = ('1','2','3'); _ce(\@lparstat);
Either you slapped use strict; at the top of your program without re-running it, or you are running other code than the code you are looking at.
Running your program with use strict; immediately lets Perl tell you what goes wrong. Another hint would be to actually print the filename you're trying to open:
open (my $i, "+<", $$name) or warn "Failed to open '$$name': $ +!"; ### FAILS HERE ###
If you're not using strict, Perl will allow you to dereference things that are not a reference. This rarely makes sense but you will actually see the contents of $$name (nothing).
Maybe that is just a typo and you wanted to use $name instead.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: opening a file passed into sub as ref
by teamassociated (Sexton) on Mar 15, 2018 at 18:06 UTC | |
by poj (Abbot) on Mar 15, 2018 at 19:02 UTC |