in reply to opening a file passed into sub as ref

print $csv "$lpname\n"; print $csv '*' x length($lpname),"\n"; print $csv "$i,\n"; print $csv "\n\nHost,Entitled CPU and RAM as of @asof,\n\n";

$csv is not a valid FILEHANDLE. It has not been opened anywhere so it cannot be printed to.

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"; }

The variable $i is first used as a FILEHANDLE and then used as text from a file. But in the line while (<$i>) { you are assigning the file text to the variable $_ which you don't use at all.

Replies are listed 'Best First'.
Re^2: opening a file passed into sub as ref
by teamassociated (Sexton) on Mar 15, 2018 at 18:59 UTC
    apologies, csv is opened in the code. i forgot to paste it. the error says $i and $i is not being opened that csv FH.