Proper indentation and alignment is a very handy thing... you close the while loop on top of your close statement for the read file handle, which means it will read the first line (ie. entry), closes the file, then fails to read the next chunk because there's no more valid handle to read from.

Is this more along the lines of what you're attempting to do (untested)?

use strict; use warnings; use File::stat; use lib "c:/strawberry/perl/site/lib"; my $files_dir = 'E:\research\audit fee models\filings\test'; my $write_dir = 'E:\research\audit fee models\filings\filenames\Exhib +it21.txt'; open my $FH_OUT, '>>',$write_dir or die "Can't open file $write_dir >: +$!>"; opendir(my $dir_handle, $files_dir) or die "Can't open directory $!"; my $file_count = 0; while (my $filename = readdir($dir_handle)){ next unless -f $files_dir.'/'.$filename; print "Processing $filename\n"; my $line_count=0; my $access_num=""; my $cik=-99; my $name=""; my $stuff=""; my $line=""; my $htm =""; open my $FH_IN, '<',$files_dir.'/'.$filename or die "Can't open $f +ilename <:$!>"; use Cwd; print getcwd(), "\n"; $/="</DOCUMENT>"; while (my $doc = <$FH_IN>){ if ($doc =~ m/^\s*<FILENAME>(.*?)(ex21)/igm ){ $htm=join('',$1,$2); print $htm; print $FH_OUT "$htm\n"; } } close $FH_IN; } close($FH_OUT);

In reply to Re: readline on closed filehandle by stevieb
in thread readline on closed filehandle by wrkrbeee

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.