You have the closing brace in the wrong place, you are closing the file after reading one line from it.
It helps to see the logic if you consistently indent one level deeper after an opening brace, and decrease indentation at the closing brace.
Code:
#!/usr/bin/perl
@FILES = ( <*sorts> );
print "@FILES ";
print "\n";
foreach $summary_x ( @FILES ) {
open(FH, "< $summary_x") or die $!;
while( <FH> ) {
chomp;
if ( /32N6524/ ) {
push (@arr_x, $summary_x);
last;
}
}
close FH;
};
print "@arr_x ";
I added the
last as a minor optimization, but otherwise, this just has the brace moved to the right place, and the single quotes changed to double quotes, and corrected indentation.
The
chomp doesn't appear to be necessary, but maybe you want to expand the script to the point where you do want lines to be chomped.
The matching on stuff with spaces in it is not a problem.