in reply to Comparing and deleting

Hi there, sounds simple enough

Would you care to show us your code? That would help in solving your problem. Don't forget to add code tags around the example.

Replies are listed 'Best First'.
Re: Re: Comparing and deleting
by kidd (Curate) on Jul 03, 2002 at 23:50 UTC
    First of all, thanks for your reply...

    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);