in reply to Re: modify the contents of an array
in thread modify the contents of an array

No it won't. It will print the return values of those s///'s which happens to be 1.

Also from perlstyle:

Avoid using grep() (or map()) or `backticks` in a void context, that is, when you just throw away their return values. Those func- tions all have return values, so use them. Otherwise use a fore- ach() loop or the system() function instead.

Replies are listed 'Best First'.
Re^3: modify the contents of an array
by Anonymous Monk on Sep 29, 2005 at 12:01 UTC
    You would be right if prasadbabu had written:
    @arr = map {s/^(\d{2})(\d{2})(\d{2})/$1\/$2\/$3/} @arr;
    But he didn't. He rightly ignored the return values of s/// (if you write s/^(\d{2})(\d{2})(\d{2})/$1\/$2\/$3/ for @arr, you are ignoring the return value of s/// just as much as when using map in void context), and went of the side effects of s/// - the main feature of s///.
      You're perfectly right. I overlooked that. Hence here are my partial apologies to prasadbabu. Partial, because map still isn't the best tool for that task.
        Well, that depends on how you describe "best tool". If best tool means "fastest" or least resource sensitive, then perl isn't the best tool for the job, as it isn't as fast as C.
Re^3: modify the contents of an array
by prasadbabu (Prior) on Sep 29, 2005 at 11:46 UTC

    blazar you are absolutely right. But the above coding works for me, i tested and then only posted.

    Hereafter i try to avoid these kind of mistakes.

    Prasad