隨筆-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
          主站蜘蛛池模板: 阳东县| 泽普县| 保德县| 麟游县| 安泽县| 华亭县| 且末县| 沽源县| 内江市| 海兴县| 呈贡县| 虹口区| 怀来县| 会理县| 彩票| 靖远县| 益阳市| 江达县| 武定县| 南华县| 曲水县| 红安县| 龙州县| 梁山县| 奉贤区| 阜宁县| 邢台县| 板桥市| 黎平县| 巫山县| 三门县| 灵寿县| 台东县| 玉山县| 文化| 和龙市| 雅安市| 和硕县| 翼城县| 宿松县| 崇阳县|