in reply to modify the contents of an array

Just to add my 2 Euro-Cent:
chomp(@array=<DATA>); s:(..)(?!$):$1/:g for @array; print join "\n", @array, ''; __DATA__ 092205 092305 092605 nonsense
Yes! This will create nonsense for non matching lines, like the last one. But I wanted to come up with a shorter RE ;-)

$\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print

Replies are listed 'Best First'.
Re^2: modify the contents of an array
by s_gaurav1091 (Beadle) on Sep 29, 2005 at 12:52 UTC
    Hi, Your solution seems to be working perfectly but I am still wondering how it happened.I am a beginner in perl ,if you dont mind can you just explain me the solution
      No problem.

      The key thing is the regular expression (..)(?!$)
      This means: Match any 2 chars ".." and remember them "()" if they are not followed by the string's end "(?!$)".
      If such a match is found, it is replaced by the 2 chars found "$1" and a slash appended, so "$1/".
      Hmmm... Not so well my explanation, I think. The idea is to find any two characters and append a slash to them The only exception is at the end of the string where no slash may be added.

      This works well for your data, but as soon as you got other data, it will produce nonsense by inserting slashes every 2 characters.

      $\=~s;s*.*;q^|D9JYJ^^qq^\//\\\///^;ex;print
        Perhaps the issue is also one of readability, I had to do a double take because you used colons as regex delimiters. I'd use tall or fat ones, like '|' or '#'.