in reply to Create a ipset for blocking networks based on internet sources
my $content = $response->content; my @network = split(/\n/,$content); @network = map { m/$regex/ ? $1 : ()} @network; ... foreach (@network) { system("ipset add temp_$set_name $_"); }
You don't do any error checking on the contents of @network so why not just:
... foreach ( $response->content =~ /$regex/g ) { system("ipset add temp_$set_name $_"); }
system("ipset create temp_$set_name $set_type"); foreach (@network) { system("ipset add temp_$set_name $_"); } system("ipset create -exist $set_name $set_type"); system("ipset swap temp_$set_name $set_name"); system("ipset destroy temp_$set_name"); my $cron_notice = "IPSet: $set_name updated (as of: $d +ate_now)."; system("logger", "-p", "cron.notice", $cron_notice);
You don't do any error checking on the system calls. Perhaps something like this:
0 == system 'ipset', 'create', "temp_$set_name", $set_ +type or warn "Cannot execute ipset because: $?";
@dates_last = $fh->getlines; @dates_last = map(m/^(\d+).*$/,@dates_last);
You don't really need two steps there and you don't really need .*$ at the end of the regular expression:
@dates_last = map /^(\d+)/, $fh->getlines;
@dates_last = split(/ /,"0 " x $urls_number)
Or just:
@dates_last = ( 0 ) x $urls_number
'(^([0-9]{1,3}\.){3}[0-9]{1,3}).*$', ... '^(\d.*\d).*$', ... '(.*)',
You should compile your regular expressions here using the qr operator and the .*$ at the end is superfluous.
qr/(^([0-9]{1,3}\.){3}[0-9]{1,3})/, ... qr/^(\d.*\d)/, ... qr/(.*)/,
@dates_now = map {$_ . "\n"} @dates_now; print $fh @dates_now;
No need for two steps:
print $fh map "$_\n", @dates_now;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Create a ipset for blocking networks based on internet sources
by mimosinnet (Beadle) on Apr 24, 2012 at 18:12 UTC | |
by jwkrahn (Abbot) on Apr 25, 2012 at 01:49 UTC | |
by mimosinnet (Beadle) on Apr 25, 2012 at 18:40 UTC | |
by jwkrahn (Abbot) on Apr 25, 2012 at 19:10 UTC | |
by mimosinnet (Beadle) on Apr 27, 2012 at 17:23 UTC |