in reply to Perl File Parsing - My Code Works, but it's Ugly!

This would be pretty trivial to clean up, but please replace your code in the original post with the code you posted in a below post.

Also, append in a different code tag section a snippet of the input file, and specify exactly what your 'search criteria' actually is, so we can test it for real.

One more thing, put:

use warnings; use strict;

at the top of your script (under the shebang line), rerun it and fix any errors that are shown.

-stevieb

Replies are listed 'Best First'.
Re^2: Perl File Parsing - My Code Works, but it's Ugly!
by Nico (Novice) on May 31, 2015 at 17:51 UTC

    Hi again!

    I just wanted to let you know I reran the script after adding the following lines:

    use warnings; use strict;

    and received a bunch of error messages in regards to "explicit package name" requirements. For example:

    Global symbol "$sec" requires explicit package name

    Time to figure out what that means!

      I figured it out! It was because I wasn't declaring my variables with "my". Will have to research why that is

Re^2: Perl File Parsing - My Code Works, but it's Ugly!
by Nico (Novice) on May 31, 2015 at 17:07 UTC
    Thank you for your reply! I have updated the code in the original post, and added what you suggested. I am going to re-run the script now and see what I get.

      Given the advice you took, no downvotes, handslaps or similar....
            BUT FOR FUTURE REFERENCE:

      Please, do NOT ever remove anything you've posted*1* because doing so can take away the context of replies you may have received (or, perhaps, are even being written as you make you change). Instead, use <strike> content to be deleted before closing the tag </strike> to disavow, show that you've changed something, etc. AND add a warning about your changes -- something like "NOTE: updated (did such and such" -- in a way that makes clear what you did and why.

      And, of course, WELCOME to PM!

      *1* There are exceptions but they are beyond the scope of this advice.


      As a newcomer, you'll find these worth reading.