Welll (drawl) .. pretty nice, but .. how about a nice little DOSKEY macro assisted by Perl, to give you a nice UNI*-style path listing if you have HOMEDRIVE defined in your ENV, or DOS-style with proper right-leaning slashes if not? ($ENV{'HOMEDRIVE'} maps a drive to the UNI* root `/'; on my system that's `D:').

Could come in handy.

ms shell> DOSKEY RPATH=perl -e "@wp=split ';', $ENV{path};@wp=map {s# +\\#/#g; $_;} @wp; @PP=($uROOT=$ENV{'HOMEDRIVE'})? map {s#\A$uROOT##i; + s#\A([^^$uROOT]) (?:\:\/)#'/'. lc ${1} .((${1} eq $uROOT)? '':'/')#x +ei;$_;} @wp : @wp; @PP=map{s#\:##; $_;} @PP; print join qq'\n', @PP;"

This is equivalent to the one-liner below (DOSKEY macros cause us to generate rather obfuscated Perl, don't they :-)?

perl -e "@wp=split ';', $ENV{path};@wp=map {s#\\#/#g; $_;} @wp; @PP=($ +uROOT=$ENV{'HOMEDRIVE'})? map {s#\A$uROOT##i; s#\A([^$uROOT]) (?:\:\/ +)#'/'. lc $1 .(($1 eq $uROOT)? '':'/')#xei;$_;} @wp : @wp; @PP=map{s# +\:##; $_;} @PP; print join qq'\n', @PP;"

On my system, to illustrate what I mean, this is output:


/console
/usr/local/bin/java/bin
/MingW32/gcc-2.95.2/bin
/bin
/ActivePERL/bin
/usr/bin
/e/scr
/c/WINNT/system32
/c/WINNT
/c/stdJava/bin
/usr/tmake/bin

Soren Andersen

Edited 2003.07.27 just clean-up.


Update 2003.08.03 -- A little observation regarding this old posting.

The code above would never have worked in MS Win9x, which has a 127-char limit on length of command lines. I have created a revised version of it which does work on Win9x, at the cost of some additional support complexity...

Update 2003.08.18 -- Refactored again since some temporary brain misfire cleared and I recalled the availability of the \l | \L operators to do what I was trying to accomplish with an eval.
DOSKEY macro in the form it takes as a macro file .mac on disk
PUP=perl -MEnv"=PATH,D0" -le"print join qq/\n/,(grep{($$D0&&s#\A$$D0## +i)or s#\A([A-Z]):#/\l$$1#i}map{s#\\#/#g;$$_}split(';',$$PATH))"
To support this, one needs to set a variable %D0% in the environment:
     SET D0=%HOMEDRIVE%

Obviously this is little more than a toy, there is very little utility to it. Still, I had some fun figuring out how to code it ;-).

The doubled-dollar signs ($$) in the code above are not dereferencing of anything in perl, they are there because as a macro on disk, the first $ will be eaten when the macro is read in by the Windows shell interpreter. They must be removed if the macro is input manually.



In reply to RE: Windows Path by Intrepid
in thread Windows Path by Adam

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.