in reply to Extract field from pipe delimited flat file

Greetings peppiv,

If all you want to do is take data from one file and dump it into another, just setup your filehandles and perform the following:

print OUTPUT join "\n", grep /\S+@\S+\.\S+/, map { split(/\|/) } <INPUT>;

The regex on the grep isn't all that great. merlyn has a few that work much better for finding all sorts of valid email addresses. However, for your example data, this works just fine.

So here's how it works (starting right, moving left):

  1. Grab the file data and use map to split every field of every line into an element of an array.
  2. Then we're going to grep that array for all elements that look like they might be email addresses.
  3. Then we're going to join that array of maybe-valid email addresses into a single string with line-breaks.
  4. Finally, print that to whatever output file you setup.

-gryphon
code('Perl') || die;