Making a SSI mode from distinguished script name

Top Japanese page




Overview

Distiguish the execution code based on the script name even though the same script. For example, there is a normal.cgi. And symbolic link it to ssimode.cgi. Then when the script is called from ssimode.cgi, execute the SSI code provided in the script.

Flow

  1. Extract the script name
  2. If the script name is for the SSI mdoe, execute the routine for that.

A sample code

 use File::Basename;
 
 my $script = basename($0);
 
 if ($script eq 'ssimode.cgi'){
   &ssimode;
 else {
   &normalmode;
 }

Description of the code

 use File::Basename;

Load File::Basename;

 my $script = basename($0);

When the perl command is executed, $0 contains the script name itself. By using basename method, it extracts command name only. i.e. exclude the path name. As a result, $script will have the script name only.

 if ($script eq 'ssimode.cgi'){
   &ssimode;
 else {
   &normalmode;
 }

If $script is ssimode.cgi, execute &ssimode. Otherwise, execute &normalmode.