perl如何输出多个匹配?
比如:
#perl
my $text = "This is a pattern test. I want to test how to output two matched patterns in one line";
if($text=~/pattern/)
{
print "$&\n";
}
只能输出一个pattern,怎么才能输出2个?
[解决办法]
my $text = "This is a pattern test. I want to test how to output two matched patterns in one line";
@all_text=$text=~/pattern/g;
foreach(@all_text)
{
print $_."\n";
}