AG87 has asked for the wisdom of the Perl Monks concerning the following question:
I want to count the number of the lines that contains keyword "energy" and the number of the lines that occur between the keyword "energy". The input file is as follows
536 ENERGY = -176.2 gagCan anyone please help me?I guess there is something wrong with while loop. Your help will really be appreciated.open(MYFILE, $data_file) || die("Could not open file!"); @raw_data=<MYFILE>; foreach $c (@raw_data) { @c = $c; (@c[0],@c[1],@c[2], @c[3], @c[4], @c[5], @c[6])=split(/\s+/,$c); if(@c[2] eq ENERGY) { #print "energy found. reading next line\n"; while(@c[2] ne ENERGY) { $_=<MYFILE>; print $_; $count = $count + 1; } } } print "$count\n"; close(MYFILE);
|
|---|