Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Can I write and close a file in a subroutine?

by davido (Archbishop)
on Nov 15, 2012 at 07:36 UTC ( #1003948=note: print w/replies, xml ) Need Help??


in reply to Can I write and close a file in a subroutine?

Are you trying to do something like this?

open my $fh, '>', 'outfile.txt'; test_and_write( $fh ); sub test_and_write { my $handle = shift; if( rand() > .5 ) { close $handle; return; } else { print $handle "Still open.\n" return 1; } }

It's possible. Maybe not a great separation of concerns, but possible.

If that's not what you're asking, read your question back to yourself and see if it makes sense to you, because it's a little opaque to me.


Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003948]
help
Chatterbox?
[stevieb]: I think that placing the * in C when dealing with pointers is akin to keeping separated the circumfix op from the inner ref in Perl: @{ $aref };, which is all personal preference. In perl, I'm good. C, don't know what I like
[stevieb]: ...yet. Still too newbie

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2017-01-24 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you watch meteor showers?




    Results (200 votes). Check out past polls.