learingperl01
MIS
Hello everyone,
hoping someone could point me in the right direction/help me out. I have the following code and not sure what the heck I am doing wrong. Here is the code that I have at the moment.
I get a bunch of correct results but for some reason the script gets stuck in a never ending loop. If I move the code the other outside of the loop I get no results, so I am not sure what is going on.
Results from all files in a directory
192.168.1.1
192.168.1.1
192.168.1.1
64.22.34.66
221.245.23.44
PASSWORD=FpnmRjE
what I want to do is remove the 192.168.1.1 dups from being printed along with all the other dups that show up.
hoping someone could point me in the right direction/help me out. I have the following code and not sure what the heck I am doing wrong. Here is the code that I have at the moment.
I get a bunch of correct results but for some reason the script gets stuck in a never ending loop. If I move the code the other outside of the loop I get no results, so I am not sure what is going on.
Code:
#!/usr/bin/perl
use strict;
use warnings;
use File::Find;
my $DIRECTORY = "/Users/data/";
find(\&edits, $DIRECTORY);
sub edits()
{
if ( -f and /.txt$/ ) { #Find files ending in .txt and drill down
all sub dirs
my $TEXT_FILE = $_; #save the results to $_;
open MATCHING_FILE, $TEXT_FILE;
my @all_lines = <MATCHING_FILE>; #Save 2 array
call all_lines
close MATCHING_FILE;
my %seen = ();
for my $each_line ( @all_lines ) {
if ( $each_line =~ /[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}\.[\d]{1,3}|
password|(ssn=)/i ) { #Search for IP or password or ssn=
$seen{$each_line}++;
}
my @uniq = keys %seen;
print @uniq;
}
}
}
Results from all files in a directory
192.168.1.1
192.168.1.1
192.168.1.1
64.22.34.66
221.245.23.44
PASSWORD=FpnmRjE
what I want to do is remove the 192.168.1.1 dups from being printed along with all the other dups that show up.