Studio:How do I extract the drive letter and use it to define the location of the Perl module?

From STRIDE Wiki
Revision as of 12:45, 11 December 2007 by Root (talk | contribs)
Jump to: navigation, search

The following code will extract the drive letter and use it to define the location of the Perl module:

use strict;
use File::Spec;
use vars qw($modulePath);
BEGIN
{
MY($vol, undef, undef) =
File::Spec->splitpath($main::ascript->Database->Path);
$modulePath = File::Spec->catpath($vol, File::Spec->catdir(' ','stride_release', 'automation', 'perl'));
$main::ascript->MessageBox($modulePath);
}
use lib qq($modulePath);
use PanelLib;

A BEGIN block is evaluated as soon as it is encountered, so the $modulePath value will have a value by the time the 'use lib' statement is encountered.

If libraries are always installed on the system drive, $ENV{'SystemDrive'} can be used to determine the volume. Alternately, a registry setting or environment variable can be used.