In the last chapterthe use of modules to implement pragmas
was discussed. One very useful pragma to aid in debugging is use
strict;. This statement does two things:
- Forces you to use the my()
function to declare all variables. When all variables have a local
scope, you avoid problems associated with unintentionally changing
the value of a variable in a function.
- Ensures that you can't use accidental symbolic dereferencing.
This topic was not covered in Chapter on References,
because it is relatively advanced. If you use the dereferencing
techniques shown in that Chapter you won't need to worry about this
requirement.
When the strict pragma is
used, your script will not compile if the preceding two rules
are violated. For example, if you tried to run the following lines
of code, debug3.pl
use strict;
$foo = { };
$bar = 5;
print("$foo\n");
print("$bar\n");
you would receive these error messages:
Global symbol "foo" requires explicit package name at test.pl line 3.
Global symbol "bar" requires explicit package name at test.pl line 4.
Global symbol "foo" requires explicit package name at test.pl line 6.
Global symbol "bar" requires explicit package name at test.pl line 7.
Execution of test.pl aborted due to compilation errors.
In order to eliminate the messages, you need to declare $foo
and $bar as local variables,
like this, debug4.pl:
use strict;
my($foo) = { };
my($bar) = 5;
print("$foo\n");
print("$bar\n");
The my()
function makes the variables local to the main
package.
In the next section, you see how to use the debugger to step through
your programs.
分享到:
相关推荐
这个问题多半是因为引用传递参数引起的,解决办法一是修改代码不使用引用传递;...或者修改函数中的引用方式即可。...今天安装ecshop的时候最上面出现了一个错误提示:Strict Standards: Only variables
其中之一便是“严格模式”(strict mode),这使得JavaScript的语法变得更加严格,旨在消除JavaScript中一些不合理的、不便于维护的特性。严格模式下,原先一些常见的导致错误的代码将不再被允许执行,其中包括强制...
( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ( xhtml1-strict.dtd ...
Most importantly, hold your own with your co-worker (and impress cocktail party guests) when he casually mentions how his HTML is now strict, and his CSS is in an external style sheet. With Head ...
随着Web技术的发展,跨域安全问题愈发突出,"Referrer-Policy : strict-origin-when-cross-origin"便是为了解决这一问题而提出的策略。本文将深入探讨这个策略的含义、作用以及如何在实际开发中应用。 一、Referrer...
3. **禁止有害操作**:严格模式禁止了一些可能导致数据损坏或者难以调试的操作,如重新定义已有的全局变量、使用`with`语句等。 4. **更好的代码风格**:严格模式鼓励开发者遵循最佳实践,避免使用可能引发问题的...
在你提供的标题和描述中,遇到的错误是“Strict Standards: Only variables should be passed by reference”,这表明你正在尝试将非变量(可能是函数的结果)作为引用传递给函数。 首先,我们来看一下错误发生的...
- 更多错误提示:例如,使用with语句、修改只读属性、在非函数上下文中使用this等,都会抛出错误。 3. **性能影响**: 严格模式并不会显著影响性能,但某些情况下可能稍微降低代码执行速度,因为引擎需要进行更多...
As a teacher, you should be patient with your students. ② 每条路旁都栽上了树。Every road is lined with trees. ③ 我们老师对工作认真,对学生也很严格。Our teacher is not only strict in his work but ...
【标题】"(转)W3C XHTML 1.0 Strict 标准模板 (GBK,UTF-8)"指的是一个遵循W3C组织制定的XHTML 1.0 Strict规范的网页模板,该模板同时支持GBK和UTF-8两种字符编码。GBK是中国大陆广泛使用的汉字编码标准,而UTF-8是...
strict
Most importantly, hold your own with your co-worker (and impress cocktail party guests) when he casually mentions how his HTML is now strict, and his CSS is in an external style sheet. With "Head ...
OOXML Strict Converter for Office 2010 allows you to open ISO strict documents that are created using Office 2013 in Office 2010. It will preserve the fidelity of the document. If you make any changes...
- be strict with:这是一个表示“对某人要求严格”的短语,如 "be strict with sb"。 - miss:这个词有多重含义,此处指“错过”,如 "miss the bus" 是“错过公交车”。 - disagree:意为“不同意”,例如 "I ...
在Laravel框架中,"Strict-Transport-Security"(简称HSTS)是一个重要的安全设置,用于增强Web应用程序的安全性。这个HTTP响应头指示浏览器只通过HTTPS与服务器进行通信,从而防止中间人攻击和SSL剥离等安全威胁。...
- 在题组训练二中,be strict with 表示“对某人要求严格”,后面接人,如第2题的She is always strict **with** us。而be strict in 表示“对某事要求严格”,后面接事物,如第1题的My parents are very strict **...
如"Our teachers are strict with us at school."表达的是老师对我们学习要求严格,而"My mother is strict in her work."指的是母亲对自己的工作标准很高。在语法结构中,"be strict with sb."是针对人,"be strict...