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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |