<?xml version="1.0" encoding="windows-1252"?>
<node id="1003948" title="Re: Can I write and close a file in a subroutine?" created="2012-11-15 02:36:55" updated="2012-11-15 02:36:55">
<type id="11">
note</type>
<author id="281137">
davido</author>
<data>
<field name="doctext">
&lt;p&gt;Are you trying to do something like this?&lt;/p&gt;
&lt;c&gt;
open my $fh, '&gt;', 'outfile.txt';

test_and_write( $fh );

sub test_and_write {
  my $handle = shift;
  if( rand() &gt; .5 ) {
    close $handle;
    return;
  }
  else {
    print $handle "Still open.\n"
    return 1;
  }
}
&lt;/c&gt;
&lt;p&gt;It's possible.  Maybe not a great separation of concerns, but possible.&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-281137"&gt;
&lt;br /&gt;&lt;p&gt;Dave&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1003947</field>
<field name="parent_node">
1003947</field>
</data>
</node>
