我使用LWP::UserAgent
和HTML::Parser
发送HTTP请求,我想在输出中检索匹配的字符串。这是输出:
OK - Number of results: 1
Name: Catalina:type=Manager,path=/xxxxxx,host=localhost
modelerType: org.apache.tomcat.util.modeler.BaseModelMBean
sessionMaxAliveTime: 29034
duplicates: 0
maxInactiveInterval: 28800
entropy: org.apache.catalina.session.StandardManager@6fefa3e7
activeSessions: 3
sessionCounter: 7
我想检索activeSessions
的值。我试过这个:
if ( $response->content()=~/activeSessions:/ ) {
print ("$1 OK\n");
}
但输出为空白。我也试过这个:
my $parser = HTML::Parser->new( 'text_h' => [ \&text_handler, 'dtext' ] );
$parser->parse( $response->decoded_content );
sub text_handler {
chomp( my $text = shift );
if ( $text =~ /activeSessions:/i ) {
print "Matched: $1\n";
}
}
但输出仍为空白。为什么呢?
答案 0 :(得分:3)
而不是
if ( $response->content()=~/activeSessions:/ ) {
print ("$1 OK\n");
}
试
if ( $response->content()=~/activeSessions:\s*(\d+)/ ) {
print ("$1 OK\n");
}