Signiant Support

Trailing Backslash Characters in Transfer Variables Cause Perl Scripts to Fail Print


During a transfer, before a script is to be executed as a transfer command, all transfer variables and keywords are substituted with their respective values. The resulting script, with all substitutions in place,is then executed on the agent machine. When using Perl as your scripting language, problems can arise when a variable or keyword contains a backslash (\) as its final character, and this variable is used as the final portion of a string.
For example, a template has a variable, %DIR%, that is prompted for at schedule time. This variable is then used in a Perl script as follows:

     my $dataDirectory='%DIR%';

If the user enters a directory that ends in a backslash, for example C:\DATA\, the agent will make the substitution, and the resulting code Perl attempts to execute is:

     my $dataDirectory='C:\DATA\';

This will cause Perl to fail with the following error:

     Can't find string terminator "'" anywhere before EOF

This is because the backslash (\) character is special in Perl. In this case, it is used to "escape" the trailing quote, thus, the string is not properly closed and an error results.

To work around the problem, you must ensure that a variable that may end in a backslash (\) character is never the final portion of a string. The easiest way to do this is to add a space to the end of the string, and then "chop" this space as soon as possible. For example:

     my $dataDirectory = '%DIR% ';     chop($dataDirectory);

Once a Perl variable has the correct value, it can be used properly in your script.

The Signiant script library contains a scriptlet, "SolutionModifyInputValue" that can be used to safely assign Signiant inputs and variables to a Perl variable:

     #!dds_perl
     %script_lib_obj:SolutionModifyInputValue%
     my $SourceAgent = ModifyInputValue(q|%src_agent% |,0);