Variables from D3 to Perl to D3?, Using Perl as a subroutine? |
![]() ![]() |
Variables from D3 to Perl to D3?, Using Perl as a subroutine? |
Sep 26 2006, 06:51 AM
Post
#1
|
|
![]() ![]() Posts: 44 |
I've got a situation where I need to pass some variables from a D3 program into a Perl script, then get a result back into D3 again.
I know I can run the Perl script with execute '!scriptname', but I'm not sure how to handle the variables. I have 10 variables going to the Perl script and 4 coming back again. The only thing that comes to mind immediately is not so elegant but I could write the 10 variables to a Linux file, then have the Perl script read that file, do its thing, then write its results to the file, and finaly have D3 read the Linux file again for the results, then delete the file so it doesn't linger. Is there a more elegant way of doing it? Thanks! -Stephanie p.s. The reason I need to do this with Perl is it's using a proprietary module that the customer supplied to do some fancy stuff with the data. So I have to utilize their Perl module to get the job done. |
|
|
|
Sep 26 2006, 08:37 AM
Post
#2
|
|
![]() ![]() ![]() Posts: 233 From: Moscow, Russia |
You may pass data through standard in/out streams.
:u bp test 01 02 data 'string1' 03 data 'string2' 04 execute '!/home/pick/ptest' capturing out 05 for i=1 to 2 06 crt out<i> 07 next i :test -string1- -string2- : ------------- :!cat /home/pick/ptest #!/usr/bin/perl $s1=<STDIN>; chomp $s1; $s2=<STDIN>; chomp $s2; print "-$s1-\n"; print "-$s2-\n"; -------- :!ls -l /home/pick/ptest -rwxr-xr-x 1 pick pick 101 Sep 26 20:49 /home/pick/ptest : --- Andrey |
|
|
|
Sep 26 2006, 09:45 AM
Post
#3
|
|
![]() ![]() Posts: 44 |
Thank you very much Andrey for the fast response!
This does exactly what I was looking for. -Stephanie |
|
|
|
Sep 26 2006, 10:01 PM
Post
#4
|
|
![]() ![]() ![]() ![]() Posts: 778 |
If you need to pass params on the commandline: execute '!/home/pick/ptest string1 string2'
and in the Perl script: CODE my $first = $ARGV[0]; When Perl code encounters an error, we use the "die" statement, which serves the same role as the BASIC STOP statement. Related to the code above, for example, the script might do something like this:my $second = $ARGV[1]; CODE my $result->DoFancyStuff( That's might be the same as:TableName => $first, RecordID => $second) or die "\!\$Error,201:$!:\n"; print $result; 1; CODE Call DoFancyStuff(result,first,second) You need to be able to distinguish between a valid result and an error coming back to your code.If result=201 then stop 201,first Also, if you are running this from a terminal session, web service, or other persistent connection, then an error in the script is going to cause your connection to abort - that's a vulnerability. The same will happen if the process takes too long, people will get tired of waiting, the connection will timeout, etc. So if the data conversion your getting from the script is either fragile or time consuming, you'll want to build a ZS command, then Execute that, rather than using Execute "!command" and holding up the user. Then you can poll some trigger file for results, provide some entertainment for the user like a Please Wait message, etc. Even Web Services can be tamed to work asynchronously and poll for results rather than waiting for them. HTH -------------------- Always visit Nebula Research and Development first for your Pick/MV solutions
New! http://twitter.com/TonyGravagno Click these links to visit Nebula R&D (Forum) (Blog) (Freeware) |
|
|
|
![]() ![]() |
| Lo-Fi Version | Time is now: 3rd September 2010 - 01:54 AM |
|
|