On Jun 7, 2005, at 15:39, Cy Kurtz wrote:

OK ... Remember you asked for it. I have at least a dozen files that I
want to update. I want to do this:

[EMAIL PROTECTED] somedirectory]$ perl -pi~ -e
's/./officers-gasenate.html/http://www.legis.state.ga.us/cgi-bin/ peo_list.pl?List=stsenatedl/' ./contactus.html

I was hoping to change this code:

State House</a> <a class="item2" href="./officers- gasenate.html">Georgia
State Senate</a></div>

to this:

State House</a> <a class="item2" href="http://www.legis.state.ga.us/ cgi-bin/peo_list.pl?List=stsenatedl">Georgia
State Senate</a></div>

Of course it isn't working. I think it's because of all of those
forward slashes. I wonder if I'm trying to drive a nail with a coffee
cup.

Excellent, thank you.

To address those kind of issues, Perl not only allows the traditional escaping solution, but also allows changing the very delimiters of s/// to avoid any escaping at all, and thus enhancing readibility. The idea is that you choose a delimiter that is not found in either part of the substitution. That is documented in perlop.

In your case, you could do for instance:

[EMAIL PROTECTED] somedirectory]$ perl -pi~ -e
's{[.]/officers-gasenate[.]html}{http://www.legis.state.ga.us/cgi-bin/ peo_list.pl?List=stsenatedl}' ./contactus.html

where the regexp is surrounded by a pair "{", "}", and so is the replacement string. Note that, in addition, the dot has been put in a class because it was being used as a metacharacter whereas a literal dot was required.

-- fxn

PS: Remember that munging HTML with regexps may be fragile unless you control the HTML and know that a regexp approach is fine.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to