仅在未加载require的情况下如何运行Perl脚本? [英] How can I run my Perl script only if it wasn't loaded with require?

查看:112
本文介绍了仅在未加载require的情况下如何运行Perl脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Perl脚本.如果是从命令行直接调用的,我要运行sub main.

I have a Perl script. If it was called direct from the command line, I want to run sub main.

如果使用require调用它,我什么也不做,等待调用者脚本在闲暇时调用sub job.

If it was called using require, I want to do nothing and wait for the caller script to call sub job at it's leisure.

推荐答案

对于代码,有一种建议的Perl解决方案,该解决方案需要可以从脚本以及perl模块中运行.

There's a recommended Perl solution for code which needs to be runnable from a script as well as a perl module.

通常称为"modulino",可用作Google或SO搜索术语以查找操作方法.

It's usually called "modulino", which can be used as Google or SO search term to find how-tos.

以下是带有参考链接的操作方法:

Here's one how-to with reference links:

可用作程序并作为模块

这篇关于仅在未加载require的情况下如何运行Perl脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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