944,184 Members | Top Members by Rank

Ad:
  • Perl Code Snippet
  • Views: 1487
  • Perl RSS
0

Need help writing a perl script to parse multiple files

by on Nov 2nd, 2009
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:
Perl Code Snippet (Toggle Plain Text)
  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. }
Comments on this Code Snippet
Nov 2nd, 2009
0

Re: Need help writing a perl script to parse multiple files

what line:13, 14 and 15 supposed to have on the initial loop?
Posting Whiz in Training
katharnakh is offline Offline
237 posts
since Jan 2006
Nov 2nd, 2009
0

Re: Need help writing a perl script to parse multiple files

Ah yes, thank you! It's printing out the required energies now.
Newbie Poster
mitzoff is offline Offline
5 posts
since Sep 2007
Message:
Previous Thread in Perl Forum Timeline: Please recommend a good "file upload" module
Next Thread in Perl Forum Timeline: Issue with Cron and Perl Script Variables





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC