I don't know what you mean by "nice and neat"? Do you want only a part of the information from each line in firewall.txt? If so, then you probably want to check split(), or maybe want to use regular expressions. You will have to give us an example of "very ugly and not very clean" and then an example of "nice and neat" if you want more help...

I have a comment on your script as it is: you are reading all of firewall.txt into memory, which can bring problems if the file gets very large. It's better if you open it and then iterate through it searching the lines that interest you. It's also a good idea to check the return values of your open() calls:

open(FW_LOG, $firewall_log) or die "$firewall_log open() failed: $!"; open(MYNEWFILE, ">>$my_new_log") or die "$my_new_log open() failed: $!"; while ($line = <FW_LOG>) { if ($line =~ /kernel Temporarily blocking host/ || $line =~ /block +ed/) { # your line transformations would go here... print MYNEWFILE $line; } } close(FW_LOG) or die "$firewall_log close() failed: $!"; close(MYNEWFILE) or die "$my_new_log close() failed: $!";

hope this helps,

update: added closing curly brace for if, removed colon at the end of filename $my_new_log


In reply to Re: My first Perl script by CukiMnstr
in thread My first Perl script by tarballed

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.