This is not in direct response to your question (g0n already answered that), but it is better practice to use lexical variables instead of barewords for filehandles. This avoids confusion with differently scoped file handles, especially with common names such as "OUTFILE".

Also, variable names in CAPS are generally frowned upon (in this case I find it particularly confusing that you use a variable name that consists of one word in caps and one in lowercase). So I'd suggest you change your code like this:

foreach my $file (@files) { my $outfile_fname = $file.".html"; # output file name open ( my $out_handle, '>', "result_dir/$outfile_fname" ) or croak "$0 : failed this file $outfile_fname : $!\n"; my $result = process($file); # You should check the return value on any file I/O operation print $out_handle $result or croak "Failed to print to $outfile_fnam +e"; close ( $out_handle ) or croak "Failed to close $outfile_fname"; }

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. -- Brian W. Kernighan

In reply to Re: Howto direct an output filehandle into directory? by tirwhan
in thread Howto direct an output filehandle into directory? by neversaint

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.