Jenda -
Got it!
this:
$_ = "c:\\Program Files\\Visual Studio\\";
print "$_\n";
s{([ \\])}{$1 eq " " ? "\\ " : "/"}ge;
print "$_\n";
works:
c:\Program Files\Visual Studio\
c:/Program\ Files/Visual\ Studio/
now it's going to take me awile to figure it out!
Aloha => Beau.
-----Original Message-----
From: Jenda Krynicky [mailto:Jenda@;Krynicky.cz]
Sent: Friday, October 25, 2002 2:27 AM
To: Beginners Perl
Subject: Re: 2 regexs into 1
From: "Beau E. Cox" <[EMAIL PROTECTED]>
> I have a file name in $_; I want to changes \s to
> /s and escape spaces.
>
> This works fine:
>
> s/\\/\//g;
> s/ /\\ /g;
>
> How can I write that as one regex?
s{([ \\])}{$1 eq '' ? '\ ' : '/'}ge;
> Again - how can I strip "s from the beginning AND
> end of a scalar w/one reges, not these two?
>
> s/^"//;
> s/"$//;
s/^"(.*)"$/$1/;
# this assumes that there is a quote both on the beginning
# and the end. So it's not strictly equivalent to those two!
s/^"?(.*?)"?$/$1/;
# this does not assume that.
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]