由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
CS版 - 继续请教perl的问题,请帮忙差错!多谢啦!
相关主题
perl 请教Re: 如今的text mining都还有什么open problem/topi
请高手帮助几道 perl 编程题 (转载)请问做web intelligence 比较强的group有哪些呀?
semantic 和 syntactic 究竟啥区别?搜索领域还有何改进的地方?
问个与semantic web 相关的journal[合集] 请问sigir和kdd怎么比?
哪位搞semantic web的大侠给指条明路?Re: for help on mmap for stdout (转载)
Semantic Web方面的paper哪些会议比较好?大家评一下,此人的水平在国内如何?
paper help...关于semantic multmedia这个方向
如今的text mining都还有什么open problem/topic新的搜索引擎Yebol
相关话题的讨论汇总
话题: stderr话题: uuid话题: option话题: message话题: shift
进入CS版参与讨论
1 (共1页)
b******e
发帖数: 432
1
希望有PERL经验的同学指点一下,多谢啦!
There are errors in the following code, both in logic
and in syntax. Find the errors and provide the correct
fixes.
# this function prints something to stdout, unless
# the option parameter is set to STDERR, and then it
# prints out to stderr
sub writeOut
{
my $message = shift;
my $option = shift; #optional
if( $option eq 'STDERR' )
{
print STDERR $message . "\n";
}
else
{
print $message . "\n";
}
}
# this function gets the system UUID, with or without
# dashes depending on the option
sub getUUID()
{
my $option = shift; #optional
my $uuid = "8f5de6fd-5f97-4b27-be35-861c3bbbb1f1";
if( $option eq 'nodash' )
{
$uuid =~ s/-//g;
}
return $uuid;
}
g**********t
发帖数: 475
2
# this function prints something to stdout, unless
# the option parameter is set to STDERR, and then it
# prints out to stderr
sub writeOut
{
my $message = shift;
my $option = shift; #optional
if( $option ne 'STDERR' )
{
print $message . "\n";
}
print STDERR $message . "\n";
}
# this function gets the system UUID, with or without
# dashes depending on the option
sub getUUID
{
my $option = shift; #optional
my $uuid = "8f5de6fd-5f97-4b27-be35-861c3bbbb1f1";
if( $option eq 'nodash' )
{
$uuid =~ s/-//g;
}
return $uuid;
}
b******e
发帖数: 432
3
能请你解释一下么?
我实在是觉得这俩段代码没啥问题。
多谢了!

【在 g**********t 的大作中提到】
: # this function prints something to stdout, unless
: # the option parameter is set to STDERR, and then it
: # prints out to stderr
: sub writeOut
: {
: my $message = shift;
: my $option = shift; #optional
: if( $option ne 'STDERR' )
: {
: print $message . "\n";

b******e
发帖数: 432
4
如果我出50伪币,有大侠帮我不?
DK
发帖数: 194
5
his fix is correct, just change ($option eq 'STDERR')
to
($option ne 'STDERR')
it should be semantically correct....
there is no syntax error here, it runs fine. even when I do "use strict;"

【在 b******e 的大作中提到】
: 能请你解释一下么?
: 我实在是觉得这俩段代码没啥问题。
: 多谢了!

b******e
发帖数: 432
6
不好意思,我真是太愚笨了。我认为对第一段代码来说这2种写法是一样的啊,都没有错误。
第二个加不加括弧的,好像都可以运行。

strict;"

【在 DK 的大作中提到】
: his fix is correct, just change ($option eq 'STDERR')
: to
: ($option ne 'STDERR')
: it should be semantically correct....
: there is no syntax error here, it runs fine. even when I do "use strict;"

b******e
发帖数: 432
7
I see. It's semantically correct! Thanks!

strict;"

【在 DK 的大作中提到】
: his fix is correct, just change ($option eq 'STDERR')
: to
: ($option ne 'STDERR')
: it should be semantically correct....
: there is no syntax error here, it runs fine. even when I do "use strict;"

b******e
发帖数: 432
8
多谢啦!!!!
这2道题我都搞明白了!
第一个是语义理解上的问题。
第二题是因为
# Functions with a prototype of () are potential candidates for inlining.
# So, it's supposed no arguments.
我明天早上再发包子哈!
b******e
发帖数: 432
9
# For this function, I think the original one is semantically wrong.
# Based on the description, I think it always needs to print to STDERR.
# However, when the option is not STDERR, it needs to print to STDOUT as
well.
#
# Besides, I may improve it by add some the restrict to input or add more
match pattern to the option, Ex:
# 1. I may trim the $option before compare.
# 1. The input option might be 'stderr', I may modify it to .
# 2. There might no input option, or no input message.
sub my_writeOut
{
my $message = shift;
my $option = shift; #optional

exit 0 if (!$message); # exit if $message is null
if( &trim($option) ne 'STDERR' )
{
print $message . "\n";
}
print STDERR $message . "\n";
}
# Functions with a prototype of () are potential candidates for inlining.
# So, the original one is supposed no arguments.
# Also, I may change the function to get $uuid from input parameters.
# Further, I may use some functions to get the system UUID.
sub my_getUUID
{
my $uuid = shift;
my $option = shift; #optional
# my $uuid = "8f5de6fd-5f97-4b27-be35-861c3bbbb1f1";
exit 0 if (!$uuid); # exit if $uuid is null
if( &trim($option) eq 'nodash' )
{
$uuid =~ s/-//g;
}
return $uuid;
}
1 (共1页)
进入CS版参与讨论
相关主题
新的搜索引擎Yebol哪位搞semantic web的大侠给指条明路?
求一个论文Semantic Web方面的paper哪些会议比较好?
投文章疑问,寻求建议,有包子发!paper help...
《挖掘社交网络》英文文字版[PDF]如今的text mining都还有什么open problem/topic
perl 请教Re: 如今的text mining都还有什么open problem/topi
请高手帮助几道 perl 编程题 (转载)请问做web intelligence 比较强的group有哪些呀?
semantic 和 syntactic 究竟啥区别?搜索领域还有何改进的地方?
问个与semantic web 相关的journal[合集] 请问sigir和kdd怎么比?
相关话题的讨论汇总
话题: stderr话题: uuid话题: option话题: message话题: shift