如何将通过 Perl 正则表达式提取的每一行放入数组中?

发布于 2024-11-09 21:35:46 字数 460 浏览 6 评论 0原文

提取后,我想把我提取的每个IP地址&在屏幕上打印到数组中。我该怎么做?这是我的代码:

#!/usr/bin/perl

use HTTP::Request;
use LWP::UserAgent;

my $url = 'http://www.game-monitor.com/';
my $request = HTTP::Request->new(GET => $url);
my $useragent = LWP::UserAgent->new();
my $response = $useragent->request($request);
my $result = $response->content;

@m = ($result =~ /\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b/sg);
foreach (@m) {
    print "$_\n";
}
}

After extracting, I want to put each IP Address I extracted & printed on the screen into an array. How can I do this? Here is my code:

#!/usr/bin/perl

use HTTP::Request;
use LWP::UserAgent;

my $url = 'http://www.game-monitor.com/';
my $request = HTTP::Request->new(GET => $url);
my $useragent = LWP::UserAgent->new();
my $response = $useragent->request($request);
my $result = $response->content;

@m = ($result =~ /\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b/sg);
foreach (@m) {
    print "$_\n";
}
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

面犯桃花 2024-11-16 21:35:46

你是什​​么意思?您的 IP 已位于数组 @m 中,但如果您想将它们放入其他内容(一次一个),您可以使用 push @somethingelse, $_

另外,您应该始终使用 strict;将这些行添加到代码顶部:

use strict;
use warnings;

What do you mean? Your IPs already are in an array, @m, but if you want to put them in something else, one at a time, you can use push @somethingelse, $_

Also, you should always use strict; Add these lines to top of your code:

use strict;
use warnings;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文