Hey All,

This will probably be a no-brainer for you peoples here, but I have a quick question.

Let's say I have a text file with the following lines.

test
test
test
test
test
test

I have figured out how to get this to work for 2 entries.  Just like this:
perl -pe 's/test/$state = not $state; $state ? "test1" : "test2"/eg;$_'

This would give me:
test1
test2
test1
test2

What I need is a way to do this more dynamically.  Let's say I wanted 5 responses instead of two.  The output would be like this:

test1
test2
test3
test4
test5
test1
etc...

Could anyone give me a couple of pointers on how to do this?  I haven't used perl very much.  But am finding a need to learn some scripting.

Thanks!

In reply to search and replace with serialized answers by TheBigAmbulance

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.