slojuggler has asked for the wisdom of the Perl Monks concerning the following question:
This code prepends a path to an NT enviromental %PATH%.
Having this code:I know my bug is in the if ($path->[0] =~ /$newpath/ ) statement, but I'm not sure how to fix the bug. How can I search for $newpath without searching for the regular expression $newpath?#!/usr/bin/perl -w use strict; my $Registry; my $newpath='C:\Perl\bin'; use Win32::TieRegistry ( TiedRef=>\$Registry, Delimiter=>"/", ArrayVal +ues=>1 ); my $env= $Registry->{"LMachine/System/CurrentControlSet/Control/". "Session Manager/Environment/"} or die "Can't open CCS/SM/Env: $^E\n"; my $path= $env->{"/PATH"} or die "Can't get PATH: $^E\n"; #Prepend to path if ($path->[0] =~ /$newpath/ ) { print "$newpath is already in your PATH\n"; } else { print "Here\n"; $path->[0]= $newpath . "$path->[0]"; print "Path is now $path->[0]\n"; $env->{"/PATH"}= $path or die "Can't set PATH: $^E\n" }
Thanks in advance.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Trying to determine if path exists in environmental variable
by dpuu (Chaplain) on Aug 16, 2002 at 23:13 UTC | |
Re: Trying to determine if path exists in environmental variable
by Zaxo (Archbishop) on Aug 16, 2002 at 23:36 UTC | |
Re: Trying to determine if path exists in environmental variable
by tachyon (Chancellor) on Aug 16, 2002 at 23:51 UTC | |
Re: Trying to determine if path exists in environmental variable
by slojuggler (Beadle) on Aug 17, 2002 at 01:38 UTC | |
(tye)Re: Trying to determine if path exists in environmental variable
by tye (Sage) on Aug 17, 2002 at 05:35 UTC | |
Re: Trying to determine if path exists in environmental variable
by slojuggler (Beadle) on Aug 16, 2002 at 23:12 UTC |