I would create an index file, where each imagename is mapped to an alt text-quip. 50 images times 20 pages is only 1000 items, so you can pull that index file into a hash for simplicity sake. In fact, since this is just a single-use script, don't bother with the text file, just put your filename (key) / text (value) pairs into a __DATA__ segment at the bottom of the script and read them into your hash with the <DATA> filehandle and a clever chomp and split.

Then you'll iterate over each html file in the directory. You might consider using something like HTML::TokeParser so that you don't have to roll your own (possibly less robust) regexp solution for finding the <img src... tags. As you locate each tag, match the image name with one of the hash keys, and presto, you'll have the text that needs to be added. You write out a new tempfile with the changes, and rename it over the old html file. Then move on to the next html file.

Be sure to keep backups until you've got it going right.


Dave


In reply to Re: Slurping and s/// a group of files from a list by davido
in thread Slurping and s/// a group of files from a list by Anonymous Monk

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.