Rather than calling open directly it would probably be better to have a routine for opening files as well as one for closing them. It would maintain a HoH, %openFiles perhaps, keyed by file name or stringified handle, that would have a key/value pair added when a file was opened. The value would be a hash reference with key/value pairs for file name, file handle and a flag for whether or not to unlink. The HoH would be iterated over by the clean-up routine to close and optionally unlink any open files. I think this would be preferable to your scheme, where you have a different number of arguments in calls to quit() depending on how far you have reached in the script. By the way, use quit( ... ) rather than &quit( ... ) unless you want the specific behaviour that the ampersand dictates.

I hope these ramblings are helpful. I'm sorry I haven't given a code example but it's way past my bedtime!

Cheers,

JohnGG


In reply to Re: Trouble Passing File Handles by johngg
in thread Trouble Passing File Handles by Photius

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.