Suppose you have to work on a project that includes some scripting language that is horribly crippled compared to Perl. For example, you are using FooScript with your graphics application, and you discover that FooScript does not have a facility for generating 'random' numbers.

This little script hacks together a FooScript file, saves it to a temporary location and runs it, all from within Perl. The neat part is, you fill in the missing features by passing them in from Perl. Moreover, because Perl allows you to use non-standard quotation delimiters, you do not have to worry about using a lot of ugly backslash and escaping characters. Your Perl looks like intelligible Perl, and your FooScript looks like intelligible FooScript.

### <region-file_info> ### main: ### - name: tryRunTempScript001 ### desc: use perl to generate a script in another language ### date: Thu Sep 16 09:09:11 2004 ### </region-file_info> ### begin_: init perl script use strict; use warnings; use lib "c:/MyPerlStuff/lib"; use MyScriptUtils; ### begin_: main perl code my $bin = "c:/FooScript/FooScript.exe"; my $ext = '.foos'; my $dd = {}; $dd->{random} = int(rand(200)); MyScriptUtils::RunTempScript(TempScript($dd), $bin , $ext); ### begin_: subroutine to define the FooScript script code sub TempScript { my $dd = shift; my $strOut = "" ### İİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİ ### İİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİ .qİ ### FooScript script language does not allow us to generate ### random numbers, so we let perl fill in the missing ### features. FooPrint("The random number is: İ.$dd->{random}.qİ") İ; ### İİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİ ### İİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİİ return($strOut); }###end_sub

Replies are listed 'Best First'.
Re: Fill in the missing features from your other script language
by VSarkiss (Monsignor) on Sep 16, 2004 at 18:37 UTC

    Um, this doesn't do much good without your MyScriptUtils module. Care to post that too?

      The module has a bunch of other mundane stuff that is not directly relevant to this coolness. Nevertheless, the MyScriptUtils::RunTempScript function is *very* simple

      It simply: 1) takes the input string (FooScript code); 2) saves it to a temp file (eg "c:\temp.foos") and; 3) runs the temp file we just created by using the perl 'system' command.

      system "$sBinPath $sTempFile";

      The code is pretty trivial, also, people have their own preferences regarding how to make a temp file, whether or not to use the 'system' command (eg for security reasons) and other side issues that are useful to bring up, but secondary to the original intent to just get the main idea out in the open.

      It should be added that this is not a preferred method, but a klunky workaround if your scripting environment doesn't support OLE, CORBA, XMLRPC, or other Perl-compatible interop facility for getting stuff into and out.

Re: Fill in the missing features from your other script language
by chanio (Priest) on Sep 17, 2004 at 05:03 UTC
    I have also thought of that coolness.

    My new one is that I have bittorrented the new KNOPPIX CD img (http://knoppix.org/) .

    Now, when booting with it inside my CD player, I have a completely working LINUX machine that I can use in any computer that has a CD reader.

    The CD also has a complete new version of Perl working. Even an Apache 1.3!

    It is cool to have all these good tools inside a single CD that doesn't need to be installed anywhere to work in a virtual PC.Your scripts should fit inside a compressed diskette.

    The limit, your imagination.

    .{\('v')/}
    _`(___)' __________________________
    Wherever I lay my KNOPPIX disk, a new FREE LINUX nation could be established.