Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Comparing and deleting

by kidd (Curate)
on Jul 03, 2002 at 23:30 UTC ( #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:<br><br><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" + "@" + "" + "'>")</script>presiona +ndo aquí</A><br> OTHER MESSAGE <script language=javascript>document.write("<a href='mai +lto:" + "other" + "@" + "" + "'>")</script>presionando aquí< +/A><br> WOW A MESSAGE <script language=javascript>document.write("<a href='mai +lto:" + "goodies" + "@" + "" + "'>")</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...


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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://179357]
and John Coltrane plays...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2017-10-17 18:10 GMT
Find Nodes?
    Voting Booth?
    My fridge is mostly full of:

    Results (235 votes). Check out past polls.