12 lines
493 B
Perl
12 lines
493 B
Perl
#!/usr/bin/perl
|
||
# 通过3个特殊变量$`、$&和$'可以保存匹配内容之前的内容,
|
||
# 匹配内容以及匹配内容之后的内容。
|
||
# 但是,只要使用了这3个变量中的任何一个,后面的所有分组效率都会降低。
|
||
# perl提供了一个p修饰符,能实现完全相同的功能:
|
||
|
||
$ans="cat sheep tiger";
|
||
$ans =~ /sheep/p;
|
||
print "${^PREMATCH}\n"; # 输出"cat "
|
||
print "${^MATCH}\n"; # 输出"sheep"
|
||
print "${^POSTMATCH}\n"; # 输出" tiger"
|