Please forgive me if I've misunderstood the question (and subsequent replies), but it sounds like searching for email addresses in the line isn't necessary -- that the email addresses are always the second element of the | separated line.

Here's a way to extract only the second element and dump it (one per line) to another file.

print OUTFILE join "\n", map { ( split( /\|/ ) )[1] } <INFILE>;

But if I may ask, why dump the email addresses into another file if you'll just need to re-open the new file to grab the email addresses for further processing? You can use this to grab the emails from your INFILE, then loop through them to perform your actual mailing:</P?

foreach my $email ( map { ( split( /\|/ ) )[1] } <INFILE> ){ # Do something with $email }

As you can see from the benchmark results below, the foreach loop isn't that much slower than throwing the data into another file, which will then need to be re-opened, re-read, re-closed.

Benchmark: timing 250000 iterations of foreachmapsplit, greprxmapsplit +, mapsplit... foreachmapsplit: 4 wallclock secs ( 3.46 usr + 0.00 sys = 3.46 CPU) + @ 72254.34/s (n=250000) greprxmapsplit: 4 wallclock secs ( 3.24 usr + 0.00 sys = 3.24 CPU) +@ 77160.49/s (n=250000) mapsplit: 4 wallclock secs ( 3.24 usr + 0.00 sys = 3.24 CPU) @ 77 +160.49/s (n=250000)

The greprxmapsplit code is gryphon's. I included it because the grep-regex/map/split consistently matched the plain map/split. One day I'll understand why :)


In reply to Re: Extract field from pipe delimited flat file by Jazz
in thread Extract field from pipe delimited flat file by peppiv

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.