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: [rovf] Stuck on how to iterate a list in a file against a logfile.: Edit Log



asandybox
Novice

Jun 19, 2012, 8:00 AM


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

Thanks rovf, here is my attempt at combining your code:


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>;
close FH or die "Cannot close $file: $!";

my $regexp='\\b('.join '|',(map { quotemeta($_) } @lines).')\\b';


while (<>) {
for my $line (@lines){
#if ($_ =~ m/.*$line.*/g) {
if ($_ =~ m/$regexp/g) {
print $_;
}
}
}


Still no luck. So what I am getting is the regex is the issue. I still don't get why something like:

if ($_ =~ m/.*$line.*/g)

Won't just print any lines with an IP followed by anything around it?


(This post was edited by asandybox on Jun 19, 2012, 8:12 AM)


Edit Log:
Post edited by asandybox (Novice) on Jun 19, 2012, 8:01 AM
Post edited by asandybox (Novice) on Jun 19, 2012, 8:12 AM


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

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