in reply to Howto direct an output filehandle into directory?
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"; }
|
|---|