Today I had to a set of email addresses, one per line, from which I had to remove the addresses of folks that said “Don’t email me.” Those emails were in a separate file, one address per line.
I figured I’d have to do this again, so I wrote a ruby script to automate it. Below, stripper.rb
#put each address in an array, remove whitespace and make it all lowercase potential_emails = IO.readlines(”potentials.txt”).map! {|email| email.strip.downcase} delete_emails = IO.readlines(”donotemail.txt”).map! {|email| email.strip.downcase} #use the beauty of ruby’s array subtraction operator puts potential_emails - delete_emails
Simple, terse and readable. Lovely!

Nate | 03-Jun-08 at 3:47 pm | Permalink
I gotta admit that’s pretty nice - three lines! It would take me considerably more in Perl…
MattK | 04-Jun-08 at 3:44 pm | Permalink
You can eventually write ANYTHING in one line of Perl.
You could definitely make this one line as well. The arrays potential_emails and delete_emails are there for readability.
it coulda been
puts IO.readLines(”potentials.txt”).map! {|email| email.strip.downcase} - IO.readlines(”donotemail.txt”).map! {|email| email.strip.downcase}
How’s that for terse?