I think it would be very useful if the scripting language implemented a means to pass arguments and return values to/from user subroutines/functions (aka scripts, I guess) without having to use global variables. (Maybe it does and I'm missing something major.)
For example, here is a simple script that gets the age of a file in seconds (perhaps this is not the best way to determine that, but I guess it works as an example):
Code: Select all
"_GetFileAge"
global $inFile; // function inputs
global $fileAge; // function outputs
global $tempDir;
$timeFile = $tempDir . "time.txt";
writefile($timeFile, "Check modified timestamp to get UTC offset", "o");
$tempModified = Property( "Write", $timeFile);
$inModified = Property( "Write", $inFile);
$fileAge = datediff($inModified, $tempModified, "s");
// how to call that function.... you have to use global variables for the inputs and the output
global $inFile, $fileAge;
$inFile = "myfile.foo";
sub _GetFileAge;
Code: Select all
"_GetFileAge($inFile)"
global $tempDir;
$timeFile = $tempDir . "time.txt";
writefile($timeFile, "Check modified timestamp to get UTC offset", "o");
$tempModified = Property( "Write", $timeFile);
$inModified = Property( "Write", $inFile);
return datediff($inModified, $tempModified, "s");
// how to call that function....
$fileAge = _GetFileAge("myfile.foo");
Code: Select all
// the function
"_JoinLines($text)"
return regexreplace($text, "(\r\n|\r|\n)", " ");
// calling it
$foo = _JoinLines($bar);