- 论坛徽章:
- 0
|
原帖由 gmxhk 于 2007-3-7 11:13 发表
Learning Perl 中的题目,请解释一下。
perl -e '$_=abc.eeeee.i;
s/(\.\w+)?$/.out/;
print;'
结果:abceeeeei.out
结果为什么不是abc.out
实话说,LZ的原始问题偶也没看明白...问了下别人解释如下:
$_=abc.eeeee.i;
This is short for:
$_ = 'abc' . 'eeeee' . 'i';
Which is the same as saying:
$_ = 'abceeeeei';
The substitution:
s/(\.\w+)?$/.out/;
Says to match a period (.) followed by one or more 'word' characters (\w+).
This pattern is enclosed in parentheses and this group should match zero or
one time. The pattern is anchored to the end of the string. Because the
pattern will always match, the replacement string '.out' will either be
appended to the string or replace any (\.\w+) pattern at the end of the string. |
|