The version converter is for quickly making two or more versions of your script because of the changes that have to be made in the local version of your script (the one used when off-line for testing) and the one you want to publish. Usually changes have to be made that include:

 

  • Some commands that do not work under windows like flock
  • Paths to files that Perl writes that are Unix specific. For example if you want to write a file like "/docs/logs/count.log", in your local version in windows, this must be changed to "count.log" or "\cgi-bin\docs\logs\count.log" if you have created those two directories under the server's root.

 

To fix these problems, you can modify your scripts code to run in two ways

 

First add somewhere in the beginning of the script this line:

 

#@Local#?#@Server if you are editing the local version or

 

#@Server#?#@Local if you are editing the server version.

 

This way OptiPerl "knows" what version is run. After adding the above, in the search menu you will see which version you are editing in the "Version: xxx" line.

 

Example

 

Enter the following lines:

 

#@Local#?#@Server

#?flock(OUTF,2);

my $semaphore_file=

'counter.sem';#?'/tmp/counter.sem';

 

Notice that in the Search menu you will get a label "Version: Local"

Now press "Swap Version", and the above will change to:

 

#@Server#?#@Local

flock(OUTF,2);#?

my $semaphore_file=

'/tmp/counter.sem';#?'counter.sem';

 

Notice that all lines with a '#?' where swapped at that point.

Also the search menu will be updated with the label "Version: Server"

If you press again "Swap" then the first version will be back again.

 

You can also add longer lines with many version remarks "#?", for example:

 

#@Version A#?#@Version B#?#@Version C

 

print "A";#?print "B";#?print "C";

 

Here each time "Swap" is pressed, the next version is selected. Accordingly the Version is update.

 

If you do not add the #@Server#?#@Local line, then the version converter will still work, but OptiPerl will not know which version you are editing.

 

icon_idea There is an advantage to letting OptiPerl knowing which version you are editing and using specifically the labels "Server" and "Local":

 

  • When opening or saving a remote file to a server, the version gets automatically converted.

 

  • The project manager will make the conversion automatically in the background before uploading.

 

Both of the above will work only if you have selected "Version convert to server" on the transfer session you are using. The update will not actually be shown in the editor, but done in the background.

 

icon_exclaim Do not use version converter remarks on the shebang of the line; the shell does not like this. The shebang is treated also when uploading, if the corresponding option has been selected in the transfer session.

 

icon_arrow Included is counter.cgi, that demonstrates writing two versions of a script.

 

 

Top  Previous  Next