AG87 has asked for the wisdom of the Perl Monks concerning the following question:
I want to add the occurrence of the "energy" at the end of each of the printed line. My input file is as follows
536 ENERGY = -176.2 gagopen(MYFILE, $data_file) || die("Could not open file!"); $b=$between=$energy=0; while (<MYFILE>) { foreach $line (<MYFILE>) { if (/\bENERGY\b/) { ++$energy; #print "$energy\n"; @line = $line; (@line[0],@line[1],@line[2], @line[3], @line[4], @line[5], @line[6])=s +plit(/\s+/,$line); if(@line[2] ne ENERGY) { if (@line[3] != 0) { print "@line[1] @line[3] \t $energy\n"; } if (@line[4] != 0) { print "@line[1] @line[4] \t $energy\n"; } if(@line[5] != 0) { print "@line[1] @line[5] \t $energy\n"; } } } } } close(MYFILE);
I have taken array for splitting the columns so that first integer in every row makes a pair with 2nd, 3rd and 4th integer of each column omitting the pairs containing zero and "energy" lines. My output generated is follows
1 2 1This code is counting the number of all lines but what i want is that upto 7th row, that is, 3 532 it should print 1 in the 3rd column as the pairs are after the first "energy" occurrence line. Then from 8th row to 14th row i-e from 1 2 to 3 532 it should print 2 in the 3rd column as the pairs are after the second "energy" occurrence. The output should be as follows.
1 2 1Any help will be appreciated as i am new to programing + perl. Thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Structure number
by CountZero (Bishop) on Dec 01, 2010 at 07:29 UTC | |
by AG87 (Acolyte) on Dec 02, 2010 at 05:58 UTC | |
by AG87 (Acolyte) on Dec 02, 2010 at 17:03 UTC | |
|
Re: Structure number
by jwkrahn (Abbot) on Dec 01, 2010 at 07:18 UTC | |
by AG87 (Acolyte) on Dec 02, 2010 at 05:51 UTC | |
by AG87 (Acolyte) on Dec 02, 2010 at 07:23 UTC | |
by jwkrahn (Abbot) on Dec 02, 2010 at 08:30 UTC | |
by AG87 (Acolyte) on Dec 02, 2010 at 09:02 UTC | |
|