Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: opening a file passed into sub as ref

by jwkrahn (Abbot)
on Mar 15, 2018 at 18:54 UTC ( [id://1210983]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1210983]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-18 01:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found