如何区分CLI和Perl中的CGI模式 [英] How to distinguish between CLI & CGI modes in Perl

查看:44
本文介绍了如何区分CLI和Perl中的CGI模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该编写一个Perl脚本,该脚本既可以在命令行中运行,也可以作为CGI脚本运行。我无法确定如何区分这两种模式。

I am supposed to write a Perl script which can be run both on the command line and as a CGI script. I haven't been able to determine how I should distinguish between the two modes.

那么您能不能让我知道如何实现逻辑?

So could you please let me know how to implement the logic?

推荐答案

您可以检查是否存在任意数量的 CGI环境变量,例如:

You can check for the presence of any number of CGI environment variables, e.g.:

if ($ENV{GATEWAY_INTERFACE})
{
      print "Content-type: text/plain\n\nLooks like I'm a CGI\n";
}
else
{
      print "I'm just a plain command line program\n";
}

这篇关于如何区分CLI和Perl中的CGI模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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