I have a text file which was originally a mysql dump of a database table. How do I write a Perl script to extract all the email addresses from this text file?
The problem I am having is that I read in the lines of the document one by one then do a regular expression, however in cases where there are more than one email address on the same line my script seems to fail.
open (FP, '<my-large-file.txt');
while($line = <FP>)
{
#if($line =~ /\s([\S]{1,80}[@]{1}[\S]{2,100})\s/)
#if($line =~ /([\S]{1,80}[@]{1}[\S]{2,100})\s/)
#if($line =~ /([\S]{1,80}[@]{1}[\S]{2,100})[,]/)
{
push(@emails, $1);
}
}
close (FP);
I have been playing with the above code but did not get the desired outcome.
Use the
/gmodifier to match a regular expression multiple times: