Consider the following:
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; }
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).

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

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.