Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Removing users from a list

by Kenosis (Priest)
on Sep 09, 2012 at 05:18 UTC ( #992558=note: print w/ replies, xml ) Need Help??


in reply to Removing users from a list

If I'm understanding your issue, you have two data sets. One contained in removelist.txt:

user1@example.com user3@example.com ...

The other in masterlist.txt:

user1@example.com user2@example.com user3@example.com USER1@EXAMPLE.COM<mailto:USER1@EXAMPLE.COM> user4@example.com user5@example.com user5@example.com<mailto:user5@example.com> ...

You want items from the first set to be removed from the second. Excellent suggestions have been offered, and this is a "classic issue."

See if the following will work for your situation:

use Modern::Perl; use File::Slurp qw/ read_file write_file /; my $removeList = join '|', map { chomp; $_ } read_file 'removelist.txt'; write_file 'finallist.txt', grep !/$removeList/i, read_file 'masterlist.txt';

With the above two data sets, here is the output to finallist.txt:

user2@example.com user4@example.com user5@example.com user5@example.com<mailto:user5@example.com>

The script only does what you mentioned, viz., joins the removelist.txt items with the pipe character (alternation operator) for a !"or" regex of email addresses used by grep on the masterlist.txt lines.

Hope this helps!


Comment on Re: Removing users from a list
Select or Download Code
Re^2: Removing users from a list
by CountZero (Bishop) on Sep 09, 2012 at 07:39 UTC
    To get a more efficient regular expression, use Regexp::Assemble to make your RE.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

      An excellent suggestion, CountZero...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2014-08-31 00:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (294 votes), past polls