Multiple problems here.
  1. $OldVariable contains characters special to the regexp engine -- prepend with \Q.
  2. The random number may be repeated.
  3. Once you've modified $code, @code isn't updated.
  4. Your code doesn't deal with multiple arrays on a line.
  5. The sigil for (scalar) array access is $, not @.
  6. You aren't modifying any arrays that aren't indexed (for instance, your code leaves my @array untouched).
  7. You're assuming there's no space between the array name and the index.
  8. You're assuming the index consists of just a number, what if it's an expression, a variable, or has whitespace?
  9. You're missing all the arrays containing capital letters, or that start with an underscore.

In reply to Re: Same problem replacing array index numbers by JavaFan
in thread Same problem replacing array index numbers by astroid96

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.