Silly me. When I posted this, I must have removed all of the pl2bat boilerplate considering it a distraction. But it wasn't pl2bat boilerplate; it was modified pl2bat stuff where the modifications were vital to the functioning of the script. The above code just doesn't work as-is. I guess nobody who bothered to try (if any) bothered to complain. Sorry about the mix-up. Below is a working version:

@rem = '--*-Perl-*-- @echo off set > %tmp%/vienv.tmp perl -x -S "%0" %TMP%/vienv.tmp if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl if %errorlevel% == 9009 echo You do not have Perl in your PATH. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul goto endofperl @rem '; #!/usr/bin/perl -w #line 15 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): $!"; print DATA "echo on\n"; 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

- tye        


In reply to Re: vienv - Edit local environment variables on Win32 (fixed) by tye
in thread 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.