隨筆-124  評論-194  文章-0  trackbacks-0

          Ways to include code/library from another file (eval, do, require and use)

          1)  do $file is like eval `cat $file`, except the former:
              1.1: searches @INC.
              1.2: bequeaths an *unrelated* lexical scope on the eval'ed code.

          2)  require $file is like do $file, except the former:
              2.1: checks for redundant loading, slipping already loaded files.
              2.2: raises an exception on failure to find, compile, or execute $file.

          3)  require Module is like require "Module.pm", except the former:
              3.1: translates each "::" into your system's directory separator.
              3.2: primes the parser to disambiguate class Module as an indirect object.

          4)  use Module is like require Module, except the former:
              4.1: loads the module at compile time, not run-time.
              4.2: imports symbols and semantics from that package to the current one.


          eval除了可以形成動態CODE外,還可以做異常捕捉:

            eval {
          ...
          };
          if ($@) {
          errorHandler($@);
          }

          $@在無異常時是NULL,否則是異常原因
          posted on 2008-08-12 10:42 我愛佳娃 閱讀(451) 評論(0)  編輯  收藏 所屬分類: Perl
          主站蜘蛛池模板: 安岳县| 河北省| 绥阳县| 汉中市| 秭归县| 手游| 大埔区| 仙居县| 保靖县| 塔城市| 霍城县| 潞西市| 水富县| 伊宁市| 越西县| 三台县| 都江堰市| 青铜峡市| 广南县| 长丰县| 城固县| 沾化县| 军事| 邵东县| 永济市| 理塘县| 嘉兴市| 沧源| 淳化县| 休宁县| 东莞市| 汽车| 右玉县| 衡阳县| 三台县| 武功县| 宝鸡市| 武威市| 湟中县| 裕民县| 贡觉县|