Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2067929
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

分类:

2008-07-02 21:59:56

require 5.006
    当版本号小于 5.006 的时候,会返回失败,从而导致模块加载失败。所以它的作用就是保证模块调用环境的 Perl 版本
  
    our和my一样,都是对变量的声明,不过our声明的是包全局变量,而 my 声明的是词法变量
    不过,经过our声明的变量,它会变得像一个词法变量一样,其实这也是our存在的目的:用来欺骗 strict pragma,使strict以为它是一个词法变量,其实却不是。
    有一个简单的办法可以理解our:
    1,把our声明的变量和my声明的当成一样。
    2,记住our和my的区别:our声明的是一个包全局变量,因此在符号表中存储(可以通过全限定在任何地方访问),而my声明的是一个真正的词法变量,只能在闭合块中访问。

our EXPR
our EXPR TYPE
our EXPR : ATTRS
our TYPE EXPR : ATTRS

    An {our} declares the listed variables to be valid globals within the enclosing block, file, or {eval}. That is, it has the same scoping rules as a ``my'' declaration, but does not create a local variable. If more than one value is listed, the list must be placed in parentheses. The {our} declaration has no semantic effect unless ``use strict vars'' is in effect, in which case it lets you use the declared global variable without qualifying(限定的,限制的) it with a package name. (But only within the lexical(字典的,此会的)scope of the {our} declaration. In this it differs from ``use vars'', which is package scoped.)
   An {our} declaration declares a global variable that will be visible across its entire lexical scope, even across package boundaries. The package in which the variable is entered is determined at the point of the declaration, not at the point of use. This means the following behavior holds:

    package Foo;
    our $bar;           # declares $Foo::bar for rest of lexical scope
    $bar = 20;



阅读(1342) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~