首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

perl怎么输出多个匹配

2012-02-22 
perl如何输出多个匹配?比如:#perlmy $text This is a pattern test. I want to test how to output two

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

热点排行