Operating System - OpenVMS
1826440 Members
3733 Online
109692 Solutions
New Discussion

Re: Using lexicals in Perl 5

 
SOLVED
Go to solution
Fredrik.eriksson
Valued Contributor

Using lexicals in Perl 5

Hi,

Just a quickie question, is there any good way to "import" a lexical value (say f$getsyi("nodename")) to a variable in perl?

I was thinking it would work as easy as just doing a write, but what device is supposed to write to perl from inside the script?

Just as an demonstrative example something like this is what I'm trying to do. I know that sys$output is way off, but since I have no clue I'll use that as the example :)

$node = `write sys$output f$getsyi("nodename")`;

Best regards
Fredrik Eriksson
4 REPLIES 4
Hein van den Heuvel
Honored Contributor
Solution

Re: Using lexicals in Perl 5

That'll work, but the executed string is subject to variable interpolation, and you will need to put 'ESCAPES', but for PERL and for DCL when using a one-liner:


$ perl -e "$node = qx(write sys\$output f\$getsyi(""nodename"")); print qq( -- $node --\n)"
-- TD183
--

Please tell us EXACTLY what you want, because perl may have a build-in. For example for a logical you want to use the 'fake' %ENV array:

$ perl -e "print $ENV{q(SYS$LOGIN)}"
USER1:[HEIN]


Hth,
Hein.




Fredrik.eriksson
Valued Contributor

Re: Using lexicals in Perl 5

Well it's actually right there what I wanted to do.

I need to store the nodename in a variable so I can distinguish which cluster machine I'm running the script on.
(Doing some monitoring stuff and need to check processes like SMTP_NODENAME_01).

Your solution worked perfectly.
$node = qx(write sys\$output f\$getsyi(""nodename""));

My mistake was that i tried to escape my quotation around nodename instead of doing ""nodename"".

Best regards
Fredrik Eriksson
Fredrik.eriksson
Valued Contributor

Re: Using lexicals in Perl 5

solution above
Ian Miller.
Honored Contributor

Re: Using lexicals in Perl 5

The VMS::system module may be helpful

http://search.cpan.org/~dsugal/VMS_System-1_04/system/system.pm
____________________
Purely Personal Opinion