是否有可能有条件地“使用bigint"?与Perl? [英] Is it possible to conditionally "use bigint" with Perl?

查看:115
本文介绍了是否有可能有条件地“使用bigint"?与Perl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以有条件地在Perl中使用模块,但是编译指示"又如何呢?我的测试表明,use bigint可能比Perl中的普通数学慢得多,并且我只需要使用它来处理64位整数,所以我只想在未使用64位整数支持构建Perl的情况下使用它.还知道如何检查Config模块的使用情况.

I know I can conditionally use a module in Perl but what about the "pragmas"? My tests have shown that use bigint can be much slower than normal math in Perl and I only need it to handle 64-bit integers so I only want to use it when Perl wasn't built with 64-bit integer support, which I also know how to check for using the Config module.

我尝试使用evalBEGIN块进行各种操作,但无法找到有条件地使用bigint的方法.我知道我可以使用Math::BigInt,但是在bigint和64位情况下都不能使用单个代码路径.

I tried various things with eval and BEGIN blocks but couldn't work out a way to conditionally use bigint. I know I can use Math::BigInt but then I can't use a single codepath for both the bigint and 64-bit cases.

推荐答案

这实际上很好:

use Config;
BEGIN {
  if (! $Config{use64bitint}) {
    require bigint;
    bigint->import;
  }
}

不同编译时间之间的交互很复杂(也许我会稍后再解释),但是可以说,由于这里没有字符串eval,bigint设置的标志将一直保留到其余时间.您将BEGIN块放入其中的文件或块.

The interaction between different compile-times is complicated (maybe I'll come back and try to explain it later) but suffice it to say that since there's no string eval here, the flag that bigint sets will persist through the rest of the file or block that you put that BEGIN block inside.

这篇关于是否有可能有条件地“使用bigint"?与Perl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆