开发者

Why the global variables in mysql.pm is not declared as our?

Quoted from mysql.pm:

   3 package DBD::mysql;
   4 use strict;
   。。。。
  17 $err = 0;>--# holds error code   for DBI::err
  18 $errstr = "";>--# holds error string for DBI::errstr
  19 $drh = undef;>--# holds driver handle once initialised

What's strange is that all my programe that use warnings; and uses this module d开发者_如何转开发oesn't give any warnings.

Why?


On line 5 of the source:

use vars qw(@ISA $VERSION $err $errstr $drh);

See use vars documentation.

It's one of the ways we were able to make globals and strict coexist before our was introduced to Perl. Though it's now considered "obsolete" (according to the documentation), it still exists in real code. I guess in some cases it fits into the category, "If it's not broken, don't fix it." You found one of those cases.


These variables are pre-declared with the vars pragma on the 5th line:

use vars qw(@ISA $VERSION $err $errstr $drh);

That's why Perl doesn't complain despite use strict being in effect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜