networkdude has asked for the wisdom of the Perl Monks concerning the following question:
I have two files; a file with the IP addresses I am looking for (IPS.txt) and a file of 40K firewall rules (rules.txt).
I am trying to use a while to load the file and use an array for the IP addresses. The foreach loop should look up each IP address in the rules file and print each matching line.
It actually works if I search for static text, but as soon as I use my array to plug in the values, it finds nothing. I wonder if it is the formatting of IP addresses or something. I'm stuck.
Here's the script:
open ( IPS, '<', "GIS_DEV_IPS.txt" ) || die "can't open IPS!"; open ( RULES, '<', "rules.txt" ) || die "can't open file!"; @IPS = <IPS>; close (IPS); chomp (@IP); while($line = <RULES>) { foreach $IP (@IPS) { if ($line =~ $IP) { print $line; } } } exit;
|
|---|