开发者

How can I put each line I extract through Perl regex into an array?

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


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜