首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >基本perl代码分解

基本perl代码分解
EN

Stack Overflow用户
提问于 2012-08-24 15:00:41
回答 2查看 268关注 0票数 1

我刚开始学习perl,在我的书中给出的示例代码中有这样一行:

代码语言:javascript
代码运行次数:0
运行
复制
#!/usr/bin/perl
@lines = `perldoc -u -f atan2`;
foreach (@lines) {
s/\w<([^>]+)>/\U$1/g;
print;
}

代码有效,这不是问题所在。此外,通过观察输入和输出,我知道这一行:

代码语言:javascript
代码运行次数:0
运行
复制
s/\w<([^>]+)>/\U$1/g;

这样做吗?

代码语言:javascript
代码运行次数:0
运行
复制
ATAN2 ARCTANGENT TAN TANGENT <--- X<atan2> X<arctangent> X<tan> X<tangent>

还有这个

代码语言:javascript
代码运行次数:0
运行
复制
MATH::TRIG::TAN <------- C<Math::Trig::tan>

我的问题是:X和C从何而来?

作为一个FYI:这是我的输出,如果我不使用代码:

代码语言:javascript
代码运行次数:0
运行
复制
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

下面是代码的完整输出:

代码语言:javascript
代码运行次数:0
运行
复制
[/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
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-24 15:10:34

代换准则

代码语言:javascript
代码运行次数:0
运行
复制
s/\w<([^>]+)>/\U$1/g;

找到一个字母数字字符(示例文本中的X和C),然后是<,捕获任何不是>的字符,然后是>。然后,它将捕获的字符串放回,并使用转义序列\U将其转换为大写。

我的问题是:X和C从何而来?

他们已经在perldoc的短信里了。然而,它们被替换正则表达式删除。也许你把输入和输出搞糊涂了。

票数 3
EN

Stack Overflow用户

发布于 2012-08-24 15:14:21

你确定你没有混淆你的输入和输出吗?在我看来,这段代码将把"z“转换成”某样东西“。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12111904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档