use命令的疑问

火山企鹅 2006-01-02 12:03:58
请问以下语句是什么意思?

1.
use vars qw(
$vars
);

2.
use lib ".";

3.
use strict;

以及这句话是什么意思:
$template->process("index.html.tmpl", $vars) || ThrowTemplateError($template->error());
这里为什么要用||
...全文
134 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
fibbery 2006-01-04
  • 打赏
  • 举报
回复
$template->process("index.html.tmpl", $vars) || ThrowTemplateError($template->error());
也许习惯了这样写的程序员不觉得什么,就是前面如果除了错误,则执行后面.这个习惯应该是从Unix和C抑或是shell中演变而来的.
但是这句话实际上借助了process函数的返回值和“||”(或)的特性。
||在perl中(c也是一样)如果左面的表达式为false,才会执行右面的表达式。
process的返回值如果为0(false)时,才会抛出(执行)右边的异常。

-----
从软件的可读性、移植性方面来说,本人不提倡这么写!我的程序也从来不会这么些!
火山企鹅 2006-01-03
  • 打赏
  • 举报
回复
我在书上没有找到,可能是我没看仔细,还请各位执教。
JoyerHuang_悦 2006-01-03
  • 打赏
  • 举报
回复
1..............
Pragma that, given a list of variable names, predeclares all variables in the list, making sure they are available to routines with delayed loading (e.g., routines loaded by the AutoLoader or SelfLoader). This allows you to use the variables under use strict. The vars pragma also disables warnings about typographical errors.

use vars qw($var1 @var2 %var3);


2..............
Permits adding additional directories to Perl's default search path at compile time. The directories are added at the front of the search path.

use lib list;
adds the directories specified in list to @INC.

3..............

Pragma for doing strict error checking within the current block. Can be turned off by prefixing with no:

use strict 'vars';
...
no strict 'vars';
Provides three kinds of restriction:

strict 'refs'
Generates runtime error if you use any symbolic references.

strict 'subs'
Generates compile-time error if you use a bareword identifier that's not a predeclared subroutine.

strict 'vars'
Generates compile-time error if you access a variable that wasn't declared via my, isn't fully qualified, or wasn't imported.

use strict by itself (with no import list) is the most restrictive, causing all possible restrictions to be imposed.
hellwolf 2006-01-02
  • 打赏
  • 举报
回复
1、2、3都可以看书阿。

$template->process("index.html.tmpl", $vars) || ThrowTemplateError($template->error());
是习惯用法,如果前面返回“非”值(通常代表失败)则执行后面的。
火山企鹅 2006-01-02
  • 打赏
  • 举报
回复
ding

37,721

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧