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 11:09, 29 February 2008 by Timd (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','lib', 'perl', 'S2S'));
}
use lib qq($modulePath);
use TestUtils;

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.