I got an array of email addresses:
@emails = ("sam\@email.com", "john\@email.com", "jenifer\@email.com");
There are 20 txt files wherefrom email addresses are being parsed. The parsed email addresses should be added to the @emails array only if they are not in it.
Example txt file contents:
===========================
Zip_Name: jenni@email.com
Zip_Name: sam@email.com
Zip_Name: dave@email.com
Zip_Name: john@email.com
Can it be done in a one-liner (checking and adding non existant array element)
My current code is following, and its not good becasue its adding the new e-mail address even if it is there already.
#READ FILE LIST
foreach my $FILES (@FILES) {
my $file=$FILES;
open(INFO,"$dir\\$file");
my @lines=<INFO>;
foreach my $line (@lines)
{
if ($line =~ /^email/){
($line =~ s/email.//);
chomp $line;
if ($line =~ /^(\w|\-|\_|\.)+\@email\.com$/)
push (@emails, $line);
}
else {
print "e-mail $line in file \"$file\" is
}
}
# email addresses come after "Zip_Name:" tag in those files
if ($line =~ /^Zip_Name\:(.*)/){
push (@sources, "$1");
}
}
}