Operating System - OpenVMS
1751786 Members
5066 Online
108781 Solutions
New Discussion юеВ

Re: Perl and awk result to a symbol/logical?

 
roose
Regular Advisor

Perl and awk result to a symbol/logical?

Hi Folks,

Is it possible to assign the result of a perl or awk command to a VMS symbol or logical? I'm initially trying to do some decimal computation and would like to use either perl or awk without piping the output to a file, then manipulate later on the value using my DCL script.

Thanks.
12 REPLIES 12
Joseph Huber_1
Honored Contributor

Re: Perl and awk result to a symbol/logical?

Get the some VMS:: packages for perl, then there is the setsym() function available.
Example:

# convert a Unix style path to VMS filespec using PERL rules
# argument 1 is the unix path (in string quotes to preserve case)
# output is in global DCL symbol VMS_FILENAME
# Author: Joseph Huber
use VMS::Filespec;
use VMS::DCLsym;
my $f = shift ;
my $x = vmsify($f) ;
#print $x;
$handle = new VMS::DCLsym;
$handle->setsym('VMS_FILENAME',$x,'GLOBAL') or die "Can't create symbol: $!\n";
http://www.mpp.mpg.de/~huber
roose
Regular Advisor

Re: Perl and awk result to a symbol/logical?

Thanks Joseph for the quick reply. I was thinking more initially of a one liner command, and I have been able to get one for perl:

$ value1 = "400"
$ value2 = "375.56"
$ perl -e "$ENV{myvalue} = sprintf(""%3.2f"",(400 - 375.56) / 375.56 * 100)"
$ show logi myvalue
"MYVALUE" = "6.51" (LNM$PROCESS_TABLE)

Now, if I would like to do such a thing using awk, how can I export awk's one liner result to a VMS logical/symbol?
labadie_1
Honored Contributor

Re: Perl and awk result to a symbol/logical?

For using awk, see the procedure typlog on dcl.openvms.org

http://dcl.openvms.org/stories.php?story=08/12/04/2298229

Instead of doing
system ("type/tail " $NF ) }

you can do
system ("def/job mylogical $NF")
or something similar.
H.Becker
Honored Contributor

Re: Perl and awk result to a symbol/logical?

If you have gnv installed you can do something simple like:

$ mc SYS$COMMON:[GNV.bin]bash. -c "x=`dcl sh sys/noproc/full` && dcl def/job x ""\""$x\""""
$ sh log x
"X" = "OpenVMS V8.3 on node BREZN 17-FEB-2010 11:27:25.03 Uptime 2 01:22:16. COMPAQ AlphaServer DS20E 833 MH." (LNM$JOB_84613700)
$

In case it is not so obvious in the used font, here: there are backticks used to assign the value to x.

But with gnv then you get dcl.c, the source code of this wrapper and then you can easily hack a:

$ mc []symfromdcl sys show sys/noproc/full
$ sh symb sys
SYS = "OpenVMS V8.3 on node BREZN 17-FEB-2010 11:27:28.47 Uptime 2 01:22:19. COMPAQ AlphaServer DS20E 833 MH."
$

(Yes, there is a \n after each output line in the symbol.)
Hein van den Heuvel
Honored Contributor

Re: Perl and awk result to a symbol/logical?

Back to Perl,

Be sure to check out the documentation
on: CLISYM_[LOCAL] and PERL_ENV_TABLES.
in: http://perldoc.perl.org/perlvms.html

You may also want to google for DCLsym.
For example:

http://www.ryerson.ca/perl/manual/vms/lib/DCLsym.html'

Regards,
Hein.
Craig A Berry
Honored Contributor

Re: Perl and awk result to a symbol/logical?

A couple more follow-ups on a Perl solution involving DCL symbols (though there's nothing wrong with using logical names if that works for you).

There is no reason, if you have Perl, to acquire extra modules in this case; VMS::DCLsym has been part of the core distribution for eons.

Although not much has changed recently, somewhat more current docs than what Hein points to are available here:

http://search.cpan.org/~dapm/perl-5.10.1/vms/ext/DCLsym/DCLsym.pm

There is nothing about the use of modules that precludes one-liners, though the command line can get on the long side:

$ perl -"MVMS::DCLsym" -e "$h=new VMS::DCLsym; $h->setsym('myvalue',sprintf(""%3.2f"",(400-375.56)/375.56*100),'GLOBAL');"
$ show symbol myvalue
MYVALUE == "6.51"

The perl command above shows up as wrapped here but fits on one line in 132-wide mode.
labadie_1
Honored Contributor

Re: Perl and awk result to a symbol/logical?

Sorry, I did a typo, the correct code looks like

system ("def/job mylogical " $NF )

John Gillings
Honored Contributor

Re: Perl and awk result to a symbol/logical?

A rather ugly and expensive, but general way to get a one line result of any command into a logical name, using PIPE:

$ PIPE perl -e "sprintf(""%3.2f"",(400 - 375.56) / 375.56 * 100)" | -
(READ SYS$PIPE v ; DEFINE/JOB/NOLOG myvalue &v)
$ show logi myvalue
"MYVALUE" = "6.51" (LNM$JOB_82874EC0)

Not the kind of thing you'd want to do in a tight loop, but the benefit is that it works for anything.

An even more general mechanism in a DCL procedure is to pipe the output of one part into another invocation of the same procedure, with some mechanism for choosing a different path.

(note that some of the other suggestions look like they involve creating a process, so are probably a similar expense as the above PIPE command).
A crucible of informative mistakes
Joseph Huber_1
Honored Contributor

Re: Perl and awk result to a symbol/logical?

>>
(note that some of the other suggestions look like they involve creating a process, so are probably a similar expense as the above PIPE command).<<

But the perl VMS::setsym() does only the one image invocation (Perl), and not 2 subprocesses like the pipe solutions.
And since the job logical table space is rather small, one should take care to deassign the logical after use!
http://www.mpp.mpg.de/~huber