由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - perl eval and if
相关主题
请教各位先贤一个Perl 问题Python problem on 64 bit Linux
请教perl的tainted和cgi::param()g++ compilation problem in linux
perl oneliner hash疑问haskell在生产环境的生产力到底如何?
IDL一问再 次 请 教 : 关 于 writing to a file 用 Perl for CGI
help!无法编译一个package这个perl的简单小程序为什么不work? (转载)
c的小问题Anyway to stop perl subroutines reading outside variable
scala最烦人的是build太不容易了perl beginner question "1;" ?
how to catch croak? (Perl)does this line get executed after exception caught
相关话题的讨论汇总
话题: eval话题: perl话题: code话题: error话题: foo
进入Programming版参与讨论
1 (共1页)
k*******3
发帖数: 1909
1
==========================TryTiny.pl CODE BEGIN====================
#!/usr/bin/perl
use warnings;
use strict;
eval
{
my $i = $foo;
};
if ($@)
{
print "There is an error caught!!!!";
}
==============================CODE END=============================
想用上面代码测试perl错误捕捉,bash下运行显示
Global symbol "$foo" requires explicit package name at TryTiny.pl line 8.
Execution of TryTiny.pl aborted due to compilation errors.
为什么没有捕捉到错误运行print "There is an error caught!!!!";这句呢?
Thanks!
j*****a
发帖数: 436
2
#!/usr/bin/perl
use warnings;
use strict;
eval 'my $i = $foo;';
if ($@)
{
print "There is an error caught!!!!";
}
k*******3
发帖数: 1909
3
为什么一定要单引号呢?
eval后面不是也可以用block吗?
下面链接说两种方法应该都可以啊
http://bbs.chinaunix.net/archiver/tid-484028.html
[code]
eval { 程序段 };
if ($@) { DOIT}
[/code]
[code]
eval ( 作为执行的字串 );
if ($@) { DOIT}
[/code]

【在 j*****a 的大作中提到】
: #!/usr/bin/perl
: use warnings;
: use strict;
: eval 'my $i = $foo;';
: if ($@)
: {
: print "There is an error caught!!!!";
: }

j*****a
发帖数: 436
4
eval block is used for run-time error, but your code is a compiler error.
k*******3
发帖数: 1909
5
Many thanks!
那eval 字符串能catch run time error吗?
j*****a
发帖数: 436
6
Yes.
1 (共1页)
进入Programming版参与讨论
相关主题
does this line get executed after exception caughthelp!无法编译一个package
Help: a Perl script question, Thanks (转载)c的小问题
java 里可以插入linux command吗? (转载)scala最烦人的是build太不容易了
问C++文件路径的问题how to catch croak? (Perl)
请教各位先贤一个Perl 问题Python problem on 64 bit Linux
请教perl的tainted和cgi::param()g++ compilation problem in linux
perl oneliner hash疑问haskell在生产环境的生产力到底如何?
IDL一问再 次 请 教 : 关 于 writing to a file 用 Perl for CGI
相关话题的讨论汇总
话题: eval话题: perl话题: code话题: error话题: foo