Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

slow to close filehandle

Status
Not open for further replies.

Smersh2000

IS-IT--Management
Dec 28, 2004
5
US
I have a problem - i have a decent size multi-dimensional array - about 150,000 rows by 300 columns. I read into it from a file, parse it couple of times and then write it into a text file in a for loop. From messages it prints i can see that the reading and parsing doesn't actually take all that long, but closing filehande takes some ridiculous time - few hours. I've tried to find some performance tips, but nothing seems to apply. What am i doing wrong?

Thanks in advance,

TS
 
It might be simply a buffering problem:


Code:
my $old_fh = select(OUTPUT_HANDLE);
$| = 1;
select($old_fh);

Otherwise, I can't really diagnose what your problem is without actually seeing some code. It should not take that long to close a file handle, so there should be an explanation for it.
 
Thank you for quick reply. I'm done for the day, so i'll test it tomorrow. In the meantime, here is the code. right after the close OUTFILHANDLE, there are lines that print some test messages, but they don't show up in the output until few hours after the "Ok"

Code:
#load details file
open (INFILEHANDLE, "<:crlf",  $detail_file_in) or die "Can't open $detail_file_in! \n";
$counter = 0;
while ($line = <INFILEHANDLE>) {
    chomp $line;
    $in_array[$counter]} = [split($in_delim, $line)];
    $counter++;
}
close INFILEHANDLE;
#process the details file
$target = 'details file';
patch_stockfiles(*LOGFILEHANDLE, *FILTERLOGFILEHANDLE, \@in_array, $target);
delete_duplicates(*LOGFILEHANDLE, *FILTERLOGFILEHANDLE, \@in_array, $target);
fix_format(*LOGFILEHANDLE, *FILTERLOGFILEHANDLE, \@in_array, $target);

($sec,$min,$hour,$day,$mon,$year) = (localtime)[0..5];
$date = sprintf "%d%02d%02d",$year+1900,$mon+1,$day;
$preform_date = $date . "\t" . $hour . ":" . $min . ":" . $sec;

print LOGFILEHANDLE         $preform_date . "\tWriting Detail File...";
print                       $preform_date . "\tWriting Detail File...";
#print into a file
open (OUTFILEHANDLE, ">" . $detail_file) or die "Can't open $detail_file \n";
for ($counter = 0; $counter <= $#in_array; $counter++) {
    print OUTFILEHANDLE join($in_delim, @{$in_array[$counter]}) . "\n";
}
@in_array = ();
print LOGFILEHANDLE         "Ok\n";
print                       "Ok\n";
close OUTFILEHANDLE;

Any ideas what i did wrong here?

Thanks,

TS
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top