Re: Parse IRC log
- From: Jim Gibson <jimsgibson@xxxxxxxxx>
- Date: Thu, 26 Jun 2008 17:17:24 -0700
In article <20080626103950.24199.qmail@xxxxxxxxxxxxxxxxxxxx>, Rara
<pleasepost@xxxxxxxxxxx> wrote:
Hello all,
I need to parse IRC logs for IPs. The format would be @ then host
followed by either ) or ], some may contain unwanted spaces. If the host
is not an IP, I would need to have it converted to an IP. The resulting
IPs would then have to be looped through Net::DNSBLLookup, with and
finally outputted to a file. Thank you for your consideration on the matter.
You can open a file for reading using open:
open( my $fh, '<', $filename ) or die("Can't open $filename: $!");
You can then read the file line-by-line by using the input operator
(<>) in a while loop:
while( my $line = <$fh> ) {
For each line, you can search for the pattern @ character followed by
some number of characters that are not either ) or ], followed by
either a ) or ], and extract the characters using a regular expression:
if( $line =~ /\@([^)\]]+)[)\]]/ ) {
my $host = $1;
You can trim unwanted spaces with tr:
$host =~ tr/ //d;
You can check to see if the host string is a numerical IP address or a
name:
if( $host =~ /^[\d.]+$/ ) {
# host is numerical
}else{
# host is a name -- look up numerical address
}
You can create a new file using open:
open( my $outh, '>', $out ) or die("Can't open $out for writing: $!");
and print lines to it with print:
print $outh "Host is $host\n";
The files will be closed automatically at the end of your program, but
you can close them explicitly and thereby check for errors:
close($outh) or die("Error closing $out: $!");
You can read about these and other Perl functions using the built-in
documentation, e.g.:
perldoc -f open
perldoc -f print
perldoc perlsyn
perldoc perlre
Good luck!
--
Jim Gibson
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
http://www.usenet.com
.
- References:
- Parse IRC log
- From: Rara
- Parse IRC log
- Prev by Date: Re: Check if directory is empty on Win32
- Next by Date: Re: isolating text in a string
- Previous by thread: Parse IRC log
- Next by thread: how to implement this with perl
- Index(es):
Relevant Pages
|