The cleanest way is to put the meat of your code in a module and have a script for each interface (CGI and command line).
You can check for CGI environment variables ( $ENV{SERVER_PROTOCOL} ) to see if CGI is used, but this will happen if the script is used as a command line script from another CGI script.
If everything you want to pass through @ARGV is form inputs, keep in mind that the CGI (module) checks the @ARGV input if the script is not called as a CGI script. See the DEBUGGING Section in the documentation .
source share