This code lets you edit your environment variables for your current command prompt. Simply run it through pl2bat (in case you don't have WinXP), put it somewhere in your PATH (like in perl/bin), set the VISUAL environment variable to your favorite editor (if you like, notepad is the default) and type vienv at the command prompt.

Then edit, copy/paste, or whatever to your environment variables. When you save and exit, the environment of the command prompt you launched it from will be changed. It just runs the code you save, so to unset an environment variable, delete everything after the "=".

                - tye
#!/usr/bin/perl -w use strict; main( @ARGV ); exit( 0 ); sub main { my( $file )= @_; my $start= tell(DATA) or die "Can't tell(DATA): $!"; open DATA, "+< $0" or die "Can't read self ($0): $!\n"; seek( DATA, $start, 0 ) or die "Can't fseek(DATA,$start,0): $!"; die "Expected :endofperl after __END__ of $0.\n" unless <DATA> =~ /^\s*:endofperl\s*$/i; open TEMP, "< $file" or die "Can't read $file: $!\n"; chomp( my @curr= <TEMP> ); close TEMP; my %curr= map { ( split /=/, $_, 2 )[0,1] } @curr; system( ( $ENV{VISUAL} || "notepad" ), qq("$file") ); open TEMP, "< $file" or die "Can't reread $file: $!\n"; chomp( my @user= <TEMP> ); close TEMP; my %user= map { ( split /=/, $_, 2 )[0,1] } @user; for my $key ( keys %user ) { if( ! exists $curr{$key} ) { next; } elsif( $curr{$key} eq $user{$key} ) { delete $user{$key}; } delete $curr{$key}; } seek( DATA, 0, 1 ) or die "Can't fseek(DATA,0,1): $!"; for my $key ( keys %curr ) { print DATA "set $key=\n"; } for my $key ( keys %user ) { print DATA qq{set $key=$user{$key}\n}; } truncate DATA, tell(DATA); } __END__ :endofperl

In reply to vienv - Edit local environment variables on Win32 by tye

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.