加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

如何检查Perl编译是否已经完成?

发布时间:2020-12-16 06:24:14 所属栏目:大数据 来源:网络整理
导读:我有一些代码要求应用程序在执行之前完全加载和编译. 有没有办法检查我的Perl程序是否仍处于编译阶段? 我有一些有用的东西,但必须有一个更好的方法: sub check_compile { printf("checkingn"); foreach my $depth (0..10) { my ($package,$filename,$line
我有一些代码要求应用程序在执行之前完全加载和编译.

有没有办法检查我的Perl程序是否仍处于编译阶段?

我有一些有用的东西,但必须有一个更好的方法:

sub check_compile {
  printf("checkingn");
  foreach my $depth (0..10) {
    my ($package,$filename,$line,$subroutine) = caller($depth);
    last unless (defined($package));

    printf("  %s %s %s %s %sn",$depth,$package,$subroutine);

    if ($subroutine =~ /::BEGIN$/) {
      printf("in compilen");
      return 1;
    }

  }

  printf("not in compilen");
  return 0;
}


BEGIN {
  check_compile();
}

use subpkg;

check_compile();

和subpkg.pm包含:

package subpkg;

use strict;
use warnings;

printf("initing subpkgn");
main::check_compile();

1; # successfully loaded

解决方法

我假设您的代码没有充分利用eval – 否则编译将与执行一起“混入” – 但您可能会考虑使用INIT和类似的块 here作为简化此操作的可能方法.

INIT blocks are run just before the Perl runtime begins execution,in “first in,first out” (FIFO) order.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读