The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 09-02-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
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.

Last edited by era; 09-02-2008 at 02:13 AM.. Reason: Remark on Useless Use of Chomp