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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |