Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

adding sys env var

by RayRay459 (Pilgrim)
on Jul 06, 2001 at 22:43 UTC ( [id://94548]=perlquestion: print w/replies, xml ) Need Help??

RayRay459 has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone help me out. I need to connect to a remote machine on the network and add a sys env variable through TieRegistry. I want to prompt for the machine name and also the name of the key and value. Using strict doesn't let me prompt for this. Can anyone please help???? ~Ray~ here's what i have..
#!/usr/bin/perl -w use strict; my $Reg; use Win32::TieRegistry ( TiedRef => \$Reg, ArrayValues => 1, Delimiter => '/', ':REG_' ); # Asking for machine name and info to be added to the sys env var print "What host would you like to connect to? "; chomp($Host = <STDIN>); print "What name would you like for the Sys Environment Variable? "; chomp($Key = <STDIN>); print "What value would you like to assign to this variable? "; chomp($Value = <STDIN>); # this is the system environment variable area my $SysEnv= $Reg->connect("$Host", "LMachine/System/CurrentControlSet/ +Control/" . "Session Manager/Environment/") or die "Can't connect to $Host 's registry or can't open Registry + key, Session Manager/Environment: $^E +\n"; # create a new value and set it's data $SysEnv->{"/$Key"} = "$Value";

Replies are listed 'Best First'.
Re: adding sys env var
by damian1301 (Curate) on Jul 06, 2001 at 22:58 UTC
    Using strict doesn't let me prompt for this.

    !!!
    strict.pm will let you prompt as long as you declare your variable lexically scoped instead of global. You could use this common example:

    chomp(my $host = <STDIN>);

    $_.=($=+(6<<1));print(chr(my$a=$_));$^H=$_+$_;$_=$^H; print chr($_-39); # Easy but its ok.
Re: adding sys env var
by MZSanford (Curate) on Jul 07, 2001 at 00:28 UTC
    also, you could add the following a line 3 :
    my ($Host,$Key,$Value);

    may the foo be with you

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://94548]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-19 13:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found