I have a script that I wrote that can either be used on the command line or as a CGI script, and need to determine how the script was called so I can output a content-type h
I usually do a little trick at the beginning of my module:
exit run(@ARGV) unless caller(); # run directly if called from command line
sub run
{
process_options(@_);
...
}
sub process_options {
@ARGV = @_;
my %opts;
GetOptions(\%opts,
...
}