Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"

Re: Re: Comparing and deleting

by kidd (Curate)
on Jul 03, 2002 at 23:50 UTC ( #179363=note: print w/replies, xml ) Need Help??

in reply to Re: Comparing and deleting
in thread Comparing and deleting

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://179363]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-03-17 06:21 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (223 votes). Check out past polls.