saintex has asked for the wisdom of the Perl Monks concerning the following question:

hello Monks,
I would like to convert a Windows path, like:

C:\Documents and Settings\user\Desktop\

in this format:

/cdrive/c/Documents and Settings/user/Desktop/

I need this in order to work with cygwin.

I wrote two regular expressions:
$path=~s#^(\w):\\#/cygdrive/$1/#; # from C:\ to /cygdrive/c/ <-- required by cgrsync $path=~s#\\#/#g; # from \ (win style) to linux style (/)
So now I have:

from:
C:\Documents and Settings\user\Desktop\
to:
/cdrive/C/Documents and Settings/user/Desktop/


but what is about the drive capital letter?
I would like to have it in lower case.

I tried with:
$path=~s#^(\w):\\#/cygdrive/lc($1)/#e;
But I have an error on this.

Any suggestion is welcome.
Thank you!

Replies are listed 'Best First'.
Re: from windows path to cygwin path
by bluescreen (Friar) on Jun 05, 2010 at 17:11 UTC
    When using /e in the search operator the right side must be a valid perl syntax, in this case perl interpreter gives you a syntax error when evaluating /cygdrive/lc($1), you have quote the strings and concatenate it with the lc call, like:
    $path=~s#^(\w):\\#"/cygdrive/".lc($1)."/"#e;
Re: from windows path to cygwin path
by Anonymous Monk on Jun 05, 2010 at 17:01 UTC
Re: from windows path to cygwin path
by Anonymous Monk on Jun 05, 2010 at 17:25 UTC
    $path=~s#^(\w):\\#/cygdrive/\L$1\E/#;
    $ perl -le"print qq!\L$ARGV[0]TALL\E!" CAPI capitall
      Thank you to all for replies!