Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Comparing and deleting

by kidd (Curate)
on Jul 03, 2002 at 23:30 UTC ( [id://179357]=perlquestion: print w/replies, xml ) Need Help??

kidd has asked for the wisdom of the Perl Monks concerning the following question:

I've got a script wich checks for certain e-mail wich I know doesnt exist anymore.

The problem its that Im using a foreach() loop(wich I think it can't be good).

I have my mail list file <email.txt> with all the emails each one in a new line:

something@greece.com<br> other@newone.nl<br> goodies@candy.net<br>

But the emails in the text against Im comparing <messages.txt> has something like this:

THIS IS A MESSAGE <script language=javascript>document.write("<a href= +'mailto:" + "something" + "@" + "greece.com" + "'>")</script>presiona +ndo aquí</A><br> OTHER MESSAGE <script language=javascript>document.write("<a href='mai +lto:" + "other" + "@" + "newone.nl" + "'>")</script>presionando aquí< +/A><br> WOW A MESSAGE <script language=javascript>document.write("<a href='mai +lto:" + "goodies" + "@" + "candy.net" + "'>")</script>presionando aqu +í</A><br>

What I want is to delete every line on "messages.txt" that has any mail on "email.txt"...

I been tryin to figure that out without any success...

Thanks

Replies are listed 'Best First'.
Re: Comparing and deleting
by Marza (Vicar) on Jul 03, 2002 at 23:37 UTC

    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.

      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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2024-04-19 20:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found