本文介绍了Perl:何时使用system()以及何时安装软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个项目中工作,该项目在系统人员维护的机器上使用Perl脚本,并且安装诸如Perl模块之类的软件包不是一件容易的事-您通常必须打电话给拥有权限的人才能这样做,请等待几天,了解该程序包的API,然后记住将其安装在已安装的每台新配置的计算机上.

I work in a project that uses Perl scripts on machines that are maintained by system folks, and installing packages such as Perl modules is no easy task - you usually have to call the person with the permissions to do that, wait several days, learn the API of the package, and then remember to install it on every newly configured machine ever installed.

很多次选择的替代方法是调用system()(或Perl内的反引号,``)并使用shell命令的输出执行所需的操作.当然,这并不总是可能的,并且在使用时,通常会在命令调用周围进行包装,但是通常更容易.

The alternative that is many times chosen is just calling system() (or backtick notation, ``, inside Perl) and using the output of the shell command that does what you want. Of course it's not always possible, and when it use, there is usually a wrapping to do around the command call, but it's generally easier.

我的问题是,根据您的经验,权衡何时会朝着双方拉拢?

My question is when is the trade-off pulling towards either side, in your experience?

添加一个示例:我想以人类可读的格式打印目录的总大小,或者列出所有大于特定大小的常规文件,并且du似乎比安装执行相同操作的模块更容易... >

adding an example:I want to print the total size of a directory in a human-readable format, or list all regular files bigger than a certain size, and du seems to make this easier than installing modules that do the same thing...

推荐答案

核心问题似乎是安装Perl模块的难度和时间长度.我将确定为什么他们在安装软件包时遇到问题,并尝试帮助简化他们的过程.

The core issue seems to be the perceived difficulty and length of time to install Perl modules. I would identify why they have problems installing the packages and try and help streamline their process.

一个常见的解决方案是修改您的过程.管理员通常不喜欢直接从CPAN安装,但是作为开发人员,您可以使用本地CPAN存储库.您可以冻结"在此使用的软件包,然后将其升级以用于生产.

A common solution is to modify your process. Admins don't typically like to install straight from CPAN, but as a developer you can use a local CPAN repo. You "freeze" the packages you use there, and then promote them for use in production.

这表示在使用模块或将其脱壳之间的权衡如下:

That said the trade-off between using modules or shelling it out as follows:

数据

模块通常返回结构化数据,脱壳返回您必须解析的非结构化文本.

Modules typically return structured data, shelling out returns unstructured text that you have to parse.

性能/资源使用情况

抽壳会创建其他整个过程,模块通常会在当前操作过程中提供功能.

Shelling out creates a whole other process, modules usually provide functionality within the current operating process.

其他依赖项

炮击使您的程序依赖于炮击的对象.请记住,某些基本程序会在操作系统和操作系统之间改变输出和行为,因此您也可能将自己耦合到特定的操作系统或一组操作系统.

Shelling out makes your program dependent on whatever you're shelling out to. Keep in mind that some basic programs change in output and behavior from OS to OS, so you may also be coupling yourself to a particular OS or set of OSes.

这篇关于Perl:何时使用system()以及何时安装软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 11:45