CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: Re: [FishMonger] Can I do an if-then-else regex mixing match and substitution?: Edit Log



poly4life
Novice

Mar 28, 2011, 8:41 AM


Views: 5634
Re: [FishMonger] Can I do an if-then-else regex mixing match and substitution?

Thank you for the suggestions.

miller's suggestion is pretty much what I was trying to accomplish.

However, I am executing this in in-place edit mode in a batch file and it's failing on the vertical bar character in my regex:


Code
if (m~[\'|\"]\d{1,2}[\'|\"]~i)...


The error is "The system cannot find the path specified."

I realize that I don't need the vertical bar character, in this case, but if I do in the future, this could be an issue. Now, I tried modifying it a couple of different ways to narrow in on the problem.

These work:

Code
if (m~[\'\"]\d{1,2}[\'\"]~i)...


Code
if (m~[\'|\"]\d{1,2}[\'\"]~i)...


This does not:

Code
if (m~[\'\"]\d{1,2}[\'|\"]~i)...


I tried escaping the vertical bar but I got the same error:

Code
if (m~[\'\"]\d{1,2}[\'\|\"]~i)...


Does anybody know what's the problem?

Update: I did manage to find the solution. The problem is I had to precede the vertical bar with the caret (^) symbol and now it enters the if loop, due to the fact that i'm executing a Perl script inside a batch file.

I also discovered that doing a match, followed by a substitution using in-place edit mode won't replace in the file. I think this is also due to the batch process. FYI, I'm using


Code
for %%X in (*.txt) do perl -pi.bak -e "Perl code" %%X


What I'm wondering is is it possible to use look-ahead or look-behind assertions in substitutions or are assertions for matching only? Either way, it appears that in-place edit won't work here and I'll have to follow your suggestions to a T, running separate perl script.

Thank you for your help.


Thank you.


(This post was edited by poly4life on Mar 28, 2011, 9:34 AM)


Edit Log:
Post edited by poly4life (Novice) on Mar 28, 2011, 8:46 AM
Post edited by poly4life (Novice) on Mar 28, 2011, 9:34 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives