Hi,
I am still learning Perl. I am trying to do the following search an replace for a txt file. But have no clue how to do this. Any help and code example is appreciated. Thanks.
Sample Data:
57KXNWLRZWJ3
057E8bf0D030
057E8bf0D032
58KXNWLRZWKB
058E8bf0D02A
058E8bf0D02C
Problem:
1. Generate a 2 digit random number. Replace the first two digits in row 1 (e.g 57) with the new number. Use the same generated number for next two rows. Repeat the process for next 3 rows and so on, till EOF.
2. generate random number to replace the last two digits in row 2 & 3 then repeat the process for 5 & 6 and so on, till EOF.
The result file will look like this. Let's say we generated a random number 12 and then next random number is 22. Also last two digits were replaced with the randomly generated numbers.
12KXNWLRZWJ3
012E8bf0D011
012E8bf0D067
22KXNWLRZWKB
022E8bf0D020
022E8bf0D023
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.