Hi!

What is your issue with the script?

In the first case, you'll need some code like

use FileHandle; my $htmlfile = new FileHandle("XXX.html", "r") ; while ($line = <$htmlfile>) { # process each line
In the second case, you need to identify what to replace and by which new text. According to your example, this could be
<a class= ----> <div class="main-button-wrapper"><a class= or <\a> ----> <\a><\div>
Then you'll need to create the perl-regExes for replacing ... using =~ s/// and escaping all special characters. One line could be
$line =~ s/<\/a>/<\/a><\/div>/;

HTH, Rata

PS.: be aware that defining suitable patterns for your anchor-tags is crucial, as the solution above is just a text-replace, but is not working on the HTML-structure. If your HTML-pages contain your anchors at "unexpected" places, you'll probably be much happier by using a CPAN-module for HTML-parsing


In reply to Re: Search and replace HTML by Ratazong
in thread Search and replace HTML by PerlRob

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.