Perl 程序从包含来自不同域的不同电子邮件 ID 的文件中读取。并通过删除域部分列出用户名。
例子:
输入文件将包含:
abc@gmail.com
xyz@yahoo.com
pqr@test.com
输出文件应如下所示:
The domain gmail.com contains following userid:
abc
The domain yahoo.com contains following userid:
xyz
The domain test.com contains following userid:
pqr
我尝试使用该代码,但它只是将域和用户名分开,而不是根据域名列出用户名。
use strict;
print "Enter the file name where emailids of different domains are present\n";
my $file=<stdin>;
open(DATA, "$file") or die ("Could not open the file\n");
while(<DATA>){
my @field=split(/@/, "$_" );
chomp $_;
my $username=@field[0];
my $domain=@field[1];
print "The user id is $username \nThe domain name is $domain \n";
}
close (DATA);