in reply to My first Perl script
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: My first Perl script
by tarballed (Initiate) on Apr 10, 2003 at 19:54 UTC |