Need help writing a perl script to parse multiple files

mitzoff 0 Tallied Votes 204 Views Share

I'm new to perl and I'm writing a script to parse multiple Gaussian03 output files and extract certain pieces of data from them.

Ideally the script needs to print out the name of each file, look for (the last) SCF Energy, the Zero-point Energy and check if the job has converged (i.e. in the file the word 'YES' will appear with some other text on four consecutive lines).

So far the script prints out the filenames and the words "Energy =" and "Zero-point energy =" but without the values it is meant to insert. I've tested this with another script and it does print out the correct values, so I'm not sure why it's not working here.

Any help would be greatly appreciated.

Here is what I've been able to write so far:


@files = grep(/\.out$/,readdir(DIR));

foreach $file (@files)
 print "$file\n";

open FILE, "<$file";

 @entry = split(/\s+/,$line);
 $Energy = $entry[5];
 $ZPE = $entry[3];

while($line = <FILE>)
 if($line =~ /SCF Done/)
   print "Energy = $Energy\n";
 if($line =~ /Zero-point correction=/)
   print "Zero-point energy = $ZPE\n";
close FILE
katharnakh 7 Posting Whiz in Training

what line:13, 14 and 15 supposed to have on the initial loop?

mitzoff 0 Newbie Poster

Ah yes, thank you! It's printing out the required energies now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.