Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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: ...

The other in masterlist.txt: USER1@EXAMPLE.COM<mailto:USER1@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:<>

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!

Replies are listed 'Best First'.
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.


    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?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2018-05-26 10:54 GMT
Find Nodes?
    Voting Booth?