隨筆-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除了可以形成動態(tài)CODE外,還可以做異常捕捉:

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

          $@在無異常時是NULL,否則是異常原因
          posted on 2008-08-12 10:42 我愛佳娃 閱讀(458) 評論(0)  編輯  收藏 所屬分類: Perl
          主站蜘蛛池模板: 永安市| 弥勒县| 胶州市| 正镶白旗| 北安市| 台中市| 万州区| 信宜市| 定兴县| 江油市| 桦甸市| 孝昌县| 体育| 和田县| 台州市| 左权县| 杨浦区| 藁城市| 崇文区| 阿城市| 庆云县| 沙坪坝区| 石渠县| 自治县| 东安县| 钟山县| 连江县| 大同县| 泾川县| 高唐县| 祥云县| 山阴县| 湖口县| 江孜县| 平顶山市| 元朗区| 定南县| 荣成市| 新龙县| 渭南市| 萨迦县|