CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [asandybox] Stuck on how to iterate a list in a file against a logfile.: Edit Log



asandybox
Novice

Jun 19, 2012, 2:47 PM


Views: 8444
Re: [asandybox] Stuck on how to iterate a list in a file against a logfile.

Guys,

After some head banging, hair pulling, I think I have a workable solution:

I went back to the drawing board with the hint that "rovf" provided and came up with the following:


Code
 
#!/usr/bin/perl
use warnings;
use strict;

my $file = "ip.txt";
open (FH, "< $file") or die "Can't open $file for read: $!";
my @lines=<FH>;
chomp @lines;
my $regexstring = join("|",@lines);
#print "($regexstring)";

while (<>) {
my $line = $_;

if ($line =~ /($regexstring)/i) {
print;
}
}

close FH or die "Cannot close $file: $!";


Appears to do the job. Don't think it's very efficient, but it works for the task at hand and I can start to munge our proxy
logs for some needed information. Thank you FishMonger and Rovf for your inputs. Very helpful for me to finally figuring things
out.


(This post was edited by asandybox on Jun 19, 2012, 2:48 PM)


Edit Log:
Post edited by asandybox (Novice) on Jun 19, 2012, 2:48 PM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives