我刚开始学习perl,在我的书中给出的示例代码中有这样一行:
#!/usr/bin/perl
@lines = `perldoc -u -f atan2`;
foreach (@lines) {
s/\w<([^>]+)>/\U$1/g;
print;
}
代码有效,这不是问题所在。此外,通过观察输入和输出,我知道这一行:
s/\w<([^>]+)>/\U$1/g;
这样做吗?
ATAN2 ARCTANGENT TAN TANGENT <--- X<atan2> X<arctangent> X<tan> X<tangent>
还有这个
MATH::TRIG::TAN <------- C<Math::Trig::tan>
我的问题是:X和C从何而来?
作为一个FYI:这是我的输出,如果我不使用代码:
perldoc -u -f atan2
=over 8
=item atan2 Y,X
X<atan2> X<arctangent> X<tan> X<tangent>
Returns the arctangent of Y/X in the range -PI to PI.
For the tangent operation, you may use the C<Math::Trig::tan>
function, or use the familiar relation:
sub tan { sin($_[0]) / cos($_[0]) }
The return value for C<atan2(0,0)> is implementation-defined; consult
your atan2(3) manpage for more information.
=back
下面是代码的完整输出:
[/cygdrive/c/Users/Documents/learn_perl]$ ./hello_world.pl
=over 8
=item atan2 Y,X
ATAN2 ARCTANGENT TAN TANGENT
Returns the arctangent of Y/X in the range -PI to PI.
For the tangent operation, you may use the MATH::TRIG::TAN
function, or use the familiar relation:
sub tan { sin($_[0]) / cos($_[0]) }
The return value for ATAN2(0,0) is implementation-defined; consult
your atan2(3) manpage for more information.
=back
发布于 2012-08-24 07:10:34
代换准则
s/\w<([^>]+)>/\U$1/g;
找到一个字母数字字符(示例文本中的X和C),然后是<
,捕获任何不是>
的字符,然后是>
。然后,它将捕获的字符串放回,并使用转义序列\U
将其转换为大写。
我的问题是:X和C从何而来?
他们已经在perldoc的短信里了。然而,它们被替换正则表达式删除。也许你把输入和输出搞糊涂了。
发布于 2012-08-24 07:14:21
你确定你没有混淆你的输入和输出吗?在我看来,这段代码将把"z“转换成”某样东西“。
https://stackoverflow.com/questions/12111904
复制相似问题