`
javatgo
  • 浏览: 1184525 次
  • 性别: Icon_minigender_2
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Being Strict with Your Variables

 
阅读更多

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.

分享到:
评论

相关推荐

    php 出现Strict Standards: Only variables should be passed by reference in的解决方法

    这个问题多半是因为引用传递参数引起的,解决办法一是修改代码不使用引用传递;...或者修改函数中的引用方式即可。...今天安装ecshop的时候最上面出现了一个错误提示:Strict Standards: Only variables

    JavaScript的strict模式与with关键字介绍

    其中之一便是“严格模式”(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 ( xhtml1-strict.dtd ...

    [深入浅出HTML].Head.First.HTML.with.CSS.and.XHTML.pdf

    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 ...

    Referrer-Policy : strict-origin-when-cross-origin解决方案

    随着Web技术的发展,跨域安全问题愈发突出,"Referrer-Policy : strict-origin-when-cross-origin"便是为了解决这一问题而提出的策略。本文将深入探讨这个策略的含义、作用以及如何在实际开发中应用。 一、Referrer...

    前端开源库-strict-mode

    3. **禁止有害操作**:严格模式禁止了一些可能导致数据损坏或者难以调试的操作,如重新定义已有的全局变量、使用`with`语句等。 4. **更好的代码风格**:严格模式鼓励开发者遵循最佳实践,避免使用可能引发问题的...

    phpdocument Strict Standards 错误解决办法

    在你提供的标题和描述中,遇到的错误是“Strict Standards: Only variables should be passed by reference”,这表明你正在尝试将非变量(可能是函数的结果)作为引用传递给函数。 首先,我们来看一下错误发生的...

    前端开源库-use-strict

    - 更多错误提示:例如,使用with语句、修改只读属性、在非函数上下文中使用this等,都会抛出错误。 3. **性能影响**: 严格模式并不会显著影响性能,但某些情况下可能稍微降低代码执行速度,因为引擎需要进行更多...

    高中英语 知识点大全137 形容词+with

    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)"指的是一个遵循W3C组织制定的XHTML 1.0 Strict规范的网页模板,该模板同时支持GBK和UTF-8两种字符编码。GBK是中国大陆广泛使用的汉字编码标准,而UTF-8是...

    strict.html

    strict

    Head+First+-+Html+With+Css+And+Xhtml

    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

    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...

    河南省开封市第三十三中学九年级英语全册 Unit 3 Teenagers should be allowed to choose

    - be strict with:这是一个表示“对某人要求严格”的短语,如 "be strict with sb"。 - miss:这个词有多重含义,此处指“错过”,如 "miss the bus" 是“错过公交车”。 - disagree:意为“不同意”,例如 "I ...

    Laravel开发-strict-transport-security

    在Laravel框架中,"Strict-Transport-Security"(简称HSTS)是一个重要的安全设置,用于增强Web应用程序的安全性。这个HTTP响应头指示浏览器只通过HTTPS与服务器进行通信,从而防止中间人攻击和SSL剥离等安全威胁。...

    全套人教版九年级英语Unit 7同步练习题及答案17精选.doc

    - 在题组训练二中,be strict with 表示“对某人要求严格”,后面接人,如第2题的She is always strict **with** us。而be strict in 表示“对某事要求严格”,后面接事物,如第1题的My parents are very strict **...

    课标版云南省中考英语总复习基础知识梳理课时9八下PPT课件.pptx

    如"Our teachers are strict with us at school."表达的是老师对我们学习要求严格,而"My mother is strict in her work."指的是母亲对自己的工作标准很高。在语法结构中,"be strict with sb."是针对人,"be strict...

Global site tag (gtag.js) - Google Analytics