You can clean that up a little:

#!/usr/bin/perl use strict; use warnings; # Parse Gaussian '03 output files for the lengths of the bonds in # Diaminopolymethine Dyes strictly between Carbon and Nitrogen or Carb +on and # Carbon chomp (my $infile = <>); chomp (my $outfile = <>); open FILE, '<', $infile or die "Unable to open $infile: $!"; my @inlog = grep {/\d/ && ! /[a-zA-Z]/ && $_ >= 1} map {split (/\s/, $_)} grep {!/h|c{3}?|nc{2}?|(estimate)|c{2}?n{1}?/} grep {/^\s?!{1}?\s*(c|n)/} <FILE>; close FILE; open LOG, '>', $outfile or die "Unable to create $outfile: $!"; print LOG join "\n", @inlog; close LOG;

Your version had some rather odd constructs. The pop loops to clear out arrays were perhaps the strangest. Much better to:

@array = ();

The while loop to slurp the file is better as:

@array = <FILE>;

The construct my $infile, my $outfile; is odd. Either my ($var1, $var1); or use two separate statements:

my $var1; my $var2;

However you should declare your variables as close to their first use as possible so it is not often that you need to declare a bunch of variables in one place like that anyway. See too the file name variable declarations in my version of your code above.

You should always use the three parameter version of open and you should always check the result.


Perl is environmentally friendly - it saves trees

In reply to Re^5: Parsing Guassian '03 Log Files by GrandFather
in thread Parsing Guassian '03 Log Files by Andrew_Levenson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.