Im very ashamed to shoq my code, since it has a lot of bugs, I dont use warnings or stricy(anyway it was only for a quick assigment)...
On the first part of the script, I open both files and using foreach I make a comparison with the grep() function...
On the second part I get the unique lines of the text, because it always repeats the same lines like a dozen times...
The problem is that the files, stays the same after all this slow proces...
Hope you can help me...
#!/usr/bin/perl #FIRST PART open(FILE, "email.txt"); @lines = <FILE>; close(FILE); open(FILE, "messages.txt"); @data = <FILE>; close(FILE); open(FILE, "+>messages.txt"); foreach $data(@data){ foreach $line(@lines){ chomp($line); ($user, $domain) = split("\@", $line); $a = grep { /$user/ } $data; $b = grep { /$domain/ } $data; if($a != 0 && $b != 0){ print $data; }else{ print FILE $data; } } } close(FILE); #SECOND PART open(FILE, "messages.txt"); @list = <FILE>; close(FILE); %seen = (); @unique = grep { ! $seen{$_} ++ } @list; open(FILE, "+>messages.txt"); foreach $unique(@unique){ print FILE "$unique"; } close(FILE);
In reply to Re: Re: Comparing and deleting
by kidd
in thread Comparing and deleting
by kidd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |