havoing trouble with text substitution
havoing trouble with text substitution
am 15.08.2007 23:06:01 von PaulS
I am trying to find any text in a file with the following characters in it:
r+c.mod
and doing a substitution as follows:
s'r+c.mod'D:/spice/r+c.mod';
but, for some reason (tell me what I am doing wrong please) PERL cannot
find the instances of r+c
Anyone have any ideas on how to get this to work?
Thanks!
P.
Re: havoing trouble with text substitution
am 15.08.2007 23:46:39 von rvtol+news
pauls schreef:
> s'r+c.mod'D:/spice/r+c.mod';
> but, for some reason (tell me what I am doing wrong please) PERL
s/PERL/Perl/
> cannot find the instances of r+c
>
> Anyone have any ideas on how to get this to work?
See `perldoc -f quotemeta`.
s{(\Qr+c.mod\E)}{D:/spice/$1};
s{(?:=\Qr+c.mod\E)}{D:/spice/};
--
Affijn, Ruud
"Gewoon is een tijger."
Re: havoing trouble with text substitution
am 15.08.2007 23:49:01 von googler
On Aug 15, 4:06 pm, pauls wrote:
> I am trying to find any text in a file with the following characters in it:
>
> r+c.mod
>
> and doing a substitution as follows:
>
> s'r+c.mod'D:/spice/r+c.mod';
>
> but, for some reason (tell me what I am doing wrong please) PERL cannot
> find the instances of r+c
>
> Anyone have any ideas on how to get this to work?
>
> Thanks!
>
> P.
You need to escape the + and the . characters with a \ . So it should
look like below (not tested though)
s'r\+c\.mod'D:/spice/r+c.mod';
Re: having trouble with text substitution
am 16.08.2007 00:20:46 von PaulS
googler wrote:
> On Aug 15, 4:06 pm, pauls wrote:
>> I am trying to find any text in a file with the following characters in it:
>>
>> r+c.mod
>>
>> and doing a substitution as follows:
>>
>> s'r+c.mod'D:/spice/r+c.mod';
>>
>> but, for some reason (tell me what I am doing wrong please) PERL cannot
>> find the instances of r+c
>>
>> Anyone have any ideas on how to get this to work?
>>
>> Thanks!
>>
>> P.
>
> You need to escape the + and the . characters with a \ . So it should
> look like below (not tested though)
> s'r\+c\.mod'D:/spice/r+c.mod';
>
brilliant, that did the trick!!
Thanks so much, you got me out of corner!
P.
Re: havoing trouble with text substitution
am 16.08.2007 00:28:26 von Gunnar Hjalmarsson
Dr.Ruud wrote:
>
> s{(?:=\Qr+c.mod\E)}{D:/spice/};
--------^
You'd better skip that colon.
But personally I would choose pinaki's solution with two plain backslashes.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Re: havoing trouble with text substitution
am 16.08.2007 00:46:47 von Tad McClellan
pauls wrote:
> I am trying to find any text in a file with the following characters in it:
>
> r+c.mod
>
> and doing a substitution as follows:
>
>
> s'r+c.mod'D:/spice/r+c.mod';
>
> but, for some reason (tell me what I am doing wrong please) PERL cannot
> find the instances of r+c
But it could find instances of rrrrrrc.
A plus sign in a regex means "one or more of the previous thing".
You need to backslash it if you want to match a literal plus sign.
> Anyone have any ideas on how to get this to work?
s#\Qr+c.mod#D:/spice/r+c.mod#;
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
Re: havoing trouble with text substitution
am 16.08.2007 10:40:25 von rvtol+news
Gunnar Hjalmarsson schreef:
> Dr.Ruud:
>> s{(?:=\Qr+c.mod\E)}{D:/spice/};
> --------^
> You'd better skip that colon.
Yes, thanks for the correction.
> But personally I would choose pinaki's solution
> with two plain backslashes.
And I wouldn't. Often these things head for using a variable.
Many s/$search/replace/ constructs should have been written
as s/\Q$search/replace/.
(The clearest exception is when $search is built with qr{}.)
--
Affijn, Ruud
"Gewoon is een tijger."
Re: havoing trouble with text substitution
am 17.08.2007 01:55:17 von Petr Vileta
pauls wrote:
> I am trying to find any text in a file with the following characters
> in it:
> r+c.mod
>
> and doing a substitution as follows:
>
>
> s'r+c.mod'D:/spice/r+c.mod';
>
> but, for some reason (tell me what I am doing wrong please) PERL
> cannot find the instances of r+c
>
You must escape + and . characters. Maybe you can use this
s#(r\+c\.mod)#D:/spice/$1#;
Note: I rather use # as alternative parentheses. The apostrophe is bad
readable for my eyes ;-)
--
Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)