Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: Filehandle in subroutine in use VRML.pm

by bliako (Monsignor)
on Jul 12, 2022 at 11:40 UTC ( [id://11145439]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Filehandle in subroutine in use VRML.pm
in thread Filehandle in subroutine in use VRML.pm

I understand that you want to pass filehandles to functions with the added feature that if user specified ...

Alas it seems I did not understand exactly. In my code above I assume that you will open a file using open my $fh, ... and that you pass around that filehandle and not a literal string/bareword representing also a filehandle, which gets complicated, having to specify also package names. So, in the code I provided the part open $fh, '>', 'xxx'; is essential. The following works for me:

{ package main; my $fh = undef; VRML::printout('some lines1', $fh); open $fh, '>', 'xxx'; VRML::printout('some lines2', $fh); close $fh; } { package VRML; sub printout { my ($lines, $_fh) = @_; my $fh = $_fh ? $_fh : *STDOUT; print $fh $lines; } }

bw, bliako

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-16 14:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found