开发者

Use a Perl Script to read a line of data from a file, and display? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably 开发者_如何学Goanswered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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";
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜