Below is code which I have written to extract unique IP+Code from
large file. (File format is ID | Time | IP | code).
I am not sure which will be best way to do this.
#!/usr/local/bin/perl
$pri_file = "out_pri.txt";
open(INFO_PRI,$pri_file)or die $!;
open(INFO,$pri_file)or die $!;
while($pri_line = <INFO_PRI>)
[rest of code snipped]
Many things I don't understand in this code, among them why you are
using 2 file handles to the same file, why you are slurping in the whole
file on one file handle and then process the file line by line on the
other file handle, why you have a nested loop, etc, etc.
Your requirements seem to be straight forward and easy to translate into
a simple algorithm (warning, sketch only, not tested):
my %idtable;
open ($F, '<', $myfile) of die "Cannot read $myfile because $!\n";
while (<$F>) { #loop through file and gather all IP | Code combinations
(undef, undef, $ip, $code) = split '\|';
$idtable{"$ip|$code"}++; #record this ip-code combination}
seek $F, 0; #reset file to start
while (<$F>) { #loop through file again and ....
(undef, undef, $ip, $code) = split '\|';
print if $idtable{"$ip|$code"} == 1;
#... print that line if the ip-code combination
#exists exactly once in the file
close $F;
jue- Hide quoted text -
- Show quoted text -