Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Some other comments, suggestions:

- There is this section where you read in the list of input files:

my @files = undef; #list of files to run script on while(my $line = <INPUT>){ chomp($line); push @files, $line; }

The @files = undef part was addressed already, but there is one more typical beginner pattern here. You read the file line by line then push every line to your array. This is inefficient and unnecessary. The <> operator in list context will read the entire file into the array for you, and you can use chomp on the array to remove newlines from every line. So a simple

my @files = <INPUT>; chomp @files;

is enough.

- I bet your script spends most of its time in the Add_Delta_DHMS function. Because you keep your dates in their complicated, human readable formats, you have to do complicated date-processing arithmetic every time you want to add 5 seconds to them. (It was the right call to use a module like Date::Calc instead of rolling your own buggy time increment code, but you pay the price for it: it's slow.) It would be better to convert the date/time you read from the first line of the file to a Unix timestamp with Time::Local, so that incrementing the rolling timestamp simply become $t += 5;, then use strftime or localtime when you print the date.

- Those chomps in the inner loop are unnecessary. If you really want to pare it down, and you are sure about your input format, you can even do away with the splits. If you have a string like "45.6, foo", and force it into scalar context (e.g. with an operator like +), Perl will take the 45.6 and ignore the rest. So you can even do something like

my $avg = <IN> + <IN> + <IN> + <IN> + <IN> + <IN> + <IN> + <IN> + <IN> + <IN> + <IN> + <IN>; $avg /= 12;

In reply to Re: What can I do to improve my code - I'm a beginner by Anonymous Monk
in thread What can I do to improve my code - I'm a beginner by Anonymous Monk

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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    [1nickt]: marto all good after the hurricane?

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (7)
    As of 2017-10-17 10:24 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My fridge is mostly full of:

















      Results (225 votes). Check out past polls.

      Notices?