Use a Perl Script to read a line of data from a file, and display? [closed]
I need some help with a script I am trying to create. Basically I have about 30 txt files, each with a email address field. for example:
example@hotmail.com
I want to be able to use a Perl script to read all of the 30 txt files, returning a list of all email addresses.
Each txt file is located in the same location, and is named like this:
1.txt, 2.txt etc. Any help is much appreciated.Do you know any Perl? I don't mind helping people with their issues, but writing code is my job, and I like to get paid for it.
Here are some hints:
- To read in the files, use the File::Find module. That'll help you find all the files you need to read in.
- You can use a hash to guarantee unique email addresses.
For example:
my %emailHash;
while (my $line = <FILE>) {
chomp $line;
if ($line =~ /[^[^\@]+\@[^\@]+\.[\w+]$/) { #Email address
$email{$line} = 1;
}
}
Now, you can use the keys function to print them out:
foreach my $email (sort keys %emailHash) {
print "Email: $email\n";
}
精彩评论