Need help writing a perl script to parse multiple files

Please support our Perl advertiser: Programming Forums - DaniWeb Sister Site
mitzoff mitzoff is offline Offline Nov 2nd, 2009, 7:05 am |
0
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:
Quick reply to this message  
Perl Syntax
  1. #!/usr/bin/perl
  2.  
  3. opendir(DIR,".");
  4. @files = grep(/\.out$/,readdir(DIR));
  5. closedir(DIR);
  6.  
  7. foreach $file (@files)
  8. {
  9. print "$file\n";
  10.  
  11. open FILE, "<$file";
  12.  
  13. @entry = split(/\s+/,$line);
  14. $Energy = $entry[5];
  15. $ZPE = $entry[3];
  16.  
  17. while($line = <FILE>)
  18. {
  19. if($line =~ /SCF Done/)
  20. {
  21. print "Energy = $Energy\n";
  22. }
  23. if($line =~ /Zero-point correction=/)
  24. {
  25. print "Zero-point energy = $ZPE\n";
  26. }
  27. }
  28. close FILE
  29. }
0
katharnakh katharnakh is offline Offline | Nov 2nd, 2009
what line:13, 14 and 15 supposed to have on the initial loop?
 
0
mitzoff mitzoff is offline Offline | Nov 2nd, 2009
Ah yes, thank you! It's printing out the required energies now.
 
 

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC