Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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


Comment on Re: Re: Comparing and deleting
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://179363]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2014-08-23 19:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (178 votes), past polls