I guess the problem you are looking into solving revolves around your regexp not extracting your data as you would like.

Maybe you should consider putting your data is a less half-assed format (yours looks like XML, but it's not even XML, so it's even worse).

Use a simpler file format, don't reinvent XML badly. If you really need XML, use a module that will help you work with _real_ XML.

Here is an example of what you could have used:

Instead of: <?--1-News1--> <b>This is option News 1 of 1</b> </?--1-News1--> <?--3-Third1of3--> <b>Option Third 1 of 3</b> </?--3-Third1of3--> what about: 1,News,1,1 3,Third,1,3 Then you can do something like: ($num, $name, $index, $total) = split /,/, $data;

Use simple data representation for simple stuff, if it get more complex look into using a database. Don't overwhelm yourself with <,>,--,/ and friends. Aim for simplicity, your problems will resolve themselves.

And finally, if you don't know what a particular piece of code in your program does (because, say, you've done some ctrl-c and some ctrl-v), remove it for now. Later, if you have a problem and you need to put it back in, you'll understand what it does.


In reply to Re: Search and Replace Text File by Schemer
in thread Search and Replace Text File 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.