Im working on a perl script to add the IP addresses from spam to my
blocked list. Each quarentined email is kept in one directory, the IP
address of the sender is in the first line of the headers. Im using
O'Reilly's "Learning Perl" as a guide and got some parts working. I can
list all the files in the directory eaisy enough,.. i was going to have
that script supply the filename and fire off another script which
searched for the IP in individual files,.. I think its a waste of
processing power to scan the entire file when i just need the first
line. Is there an eaisy way to limit the search to the first line?
some code
the first one returns each filename in the directory.
----------------------------
#!/usr/bin/perl -w
use strict;
my $file;
my $dir = "mail/";
opendir(BIN, $dir) or die "Can't open $dir: $!";
while( defined ($file = readdir BIN) ) {
next if $file =~ /^\.\.?$/; # skip . and ..
print "$file\n" if -T "$dir/$file";
}
closedir(BIN);
-----------------------------
the second one searches a single file for IP addresses. (I left in my
failed attempts to get the regex correct,.. figured it might make
someone happy to know that there are worse coders out there than themselves)
------------------------------
#!/usr/bin/perl -w
use strict;
while (<>){
if (/\d+\.\d+\.\d+\.\d+/){
#if (/\(*\)/){ #search for anything in brackets
#if (/\d\.\d\.\d\.\d/){ # search for digit.digit.digit.digit
#if (/([1-255]\.[0-255]\.[0-255]\.[0-255])/) { #another atempt
print "$&\n";
}
}
------------------------------
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>