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!
I gotta admit that’s pretty nice – three lines! It would take me considerably more in Perl…
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?