在 Perl 中优雅地确定系统架构 [英] Elegantly Determining System Architecture Within Perl

查看:25
本文介绍了在 Perl 中优雅地确定系统架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种简单的方法来从 Perl 5 中确定系统是 32 位还是 64 位.我已经前后阅读了 perlvar 手册页,但没有发现一个包含系统 CPU 架构的变量(编译 Perl 的 CPU 架构将足够接近).这是我最近的一次:

I'm looking for a simple way to determine whether a system is 32- or 64-bit from within Perl 5. I have read the perlvar manual page backwards and forwards, and have not discovered a variable that contains the system's CPU architecture (the CPU architecture Perl was compiled for will come close enough). This is the closest I have come:

chomp (my $arch = `uname -m`);

我想知道是否有更优雅的方法来确定这一点;我讨厌依赖反引号表达式,因为它们都是瓶颈,往往不安全,并且经常(尤其是这个例子)破坏跨平台兼容性.Perl 没有理由不提供这些信息.

I was wondering if there was a more elegant way of determining this; I hate relying on backtick expressions, as they are both a bottleneck, tend to be insecure, and often (this example especially) break cross-platform compatibility. There is no reason Perl shouldn't already have this information available.

推荐答案

Config 模块.

也许检查是否设置了 $Config{'archname64'} 就足够了.

Maybe checking whether $Config{'archname64'} is set would be sufficient.

这篇关于在 Perl 中优雅地确定系统架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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