On UNIX you have to escape the whitespace, e.g.

/this path/has spaces

would become

/this\ path/has\ spaces

The expression

$path_elem =~ s{(\s)}{\\$1}gio;

should do the trick.

Note that I used {} delimiters (i.e. s{}{}) to make it clearer, since the data itself contains /s and someone might get confused that a / was part of the match or substitution, rather than a delimiter. But you still could use s///, if you prefer. Also, \\ is necessary in the substituion value, since \ itself is a metacharacter in a regex.

Cheers,
Richard

Cai, Lucy (L.) wrote:

Hi All,

I am meeting a problem on a regular expression.

My code is like:

$path_elem = "$ENV{'CLEARCASE_PN'}";

The return value of $path_elem is either
$path_elem = /ccstore/test/test.pl

Or $path_elem = /ccstore/test 1/test 1.pl  # there is a space in the
path name including the file name too

There is no rule whether there is a space in the path name or not. How
can I handle it in regular expression, because when I pass the value
$path_elem to a function, if there is a space in the path name, it will
treat it 2 file path name, instead of one.

I used the following code

$path_elem = "\"$ENV{'CLEARCASE_PN'}\"";
It works fine for windows, but does not works fine on unix.

I really appriciate your great help.

Thanks

Lucy

- *** Richard A. Wells, [EMAIL PROTECTED], +1.978.371.7425
*** Reality And Wonder, http://www.raw.com/


_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to