Why do you not want to open the files for reading? How do you expect to read that one line without opening the file? Imagine the concept of finding one particular sentence in a book, without opening the book. There is no way to see what is not available to be seen. An un-opened file's contents are not available to be seen.

I would do it like this:

my @cqafiles = glob( "$cqapath/cqa_*" ); open( STATUS, '>', "cqapath/CQA_STATUS" ) or die "Can't open file $cqapath/CQA_STATUS for writing." . "\n$!"; foreach my $file ( @cqafiles ) { open my $handle, '<', $file or die "Can't open $file.\n$!"; FINDLINE: while( my $line = <$handle> ) { next unless $line =~ m/^CQA_STATUS/; $line =~ s/^[^,]+//; print STATUS $line; last FINDLINE; } } close STATUS or die "Can't close status file\n$!";

This is an untested snippet. It will still need your first few lines to set things up. ...give it a try. ;)


Dave


In reply to Re: extract a single line from multiple files in a folder. by davido
in thread extract a single line from multiple files in a folder. by august3

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.