I think that having only one instance of IO::File will help (but I haven't tested this). Also, having something besides $_ as the "foreach" loop variable could make a difference, since you are also using $_ to iterate in the "while" loop, which might cause unexpected consequences (e.g. changing the strings that are used as the keys in %altnames).use IO::File (); ## local $/; # you're not using this my $fh = IO::File->new(); # declare this just once foreach $file (sort keys %altnames) { my ($hr_title) = ( $file =~ m/(.*)\.txt/ ); print "<hr> <h1 align=center> $hr_title </h1>\n"; # don't need parens for print ... $fh->open( "$dir/$file" ) or die $!; # you gotta check! while (<$fh>) { print; } $fh->close; }
update: I rigged up five dummy files with names as indicated in your error messages, and tested your original code with perl 5.8.0 on linux SuSE 7.3 -- didn't get any errors, so I'm at a loss. The comment about altering the hash key strings in the while loop was misguided; still, it seems better to have the outer loop using an iterator variable that's different from the inner loop. Anyway, my version ran as well (after I fixed a missing dash character in the "IO::File->new()" line).
In reply to Re: Unbalance string table refcount
by graff
in thread Unbalance string table refcount
by Lhamo Latso
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |