in reply to printing enviroment vars from regex

It's not homework is it?

No need to use a regex:

my @output = split(/\n/, `set`); my %environment; foreach (@output) { my ($key, $value)= split /=/; $environment{$key}=$value; } foreach $variable qw/USERNAME HOMEDRIVE/ { ${$variable}=$environment{$variable}; } print "my name is $USERNAME my home is at $HOMEDRIVE";
Output:
my name is KJM my home is at C:
I had to adapt the environment variables a bit as I'm on Windows XP.

Update: I should have used the %ENV-hash, but TIMTOWTDI!

CountZero

"If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Replies are listed 'Best First'.
Re^2: printing enviroment vars from regex
by RnC (Sexton) on Aug 03, 2004 at 15:15 UTC
    No, it's not homework. :-) and thanks for the help.