Jenda -

Thanks, #2 I understand.

Tried #1:

$_ = 'c:\Program Files\Visual Studio\';
print "$_\n";

s{([ \\])}{$1 eq '' ? '\ ' : '/'}ge;
print "$_\n";

got:

String found where operator expected at t01.pl line 4, near "s{([ \\])}{$1
eq '' ? '"
Backslash found where operator expected at t01.pl line 4, near "' ? '\"
        (Missing operator before \?)
syntax error at t01.pl line 4, near "s{([ \\])}{$1 eq '' ? '"
Can't find string terminator "'" anywhere before EOF at t01.pl line 4.

(tried on both Linux and W2K w/Perl 5.6.1)

I am having trouble fixing it...

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]

Reply via email to