in reply to Re^2: Better Way of Manipulating Array Elements
in thread Better Way of Manipulating Array Elements

You are missing that he want's a blanks after the commas. And I improve (golfwise) to:

perl -pe's/(d)/new($1)/; s/\n/, / unless eof'

But since capturing a literal regex is silly anyway, the best I can think of at the moment is

perl -pe's/d/new(d)/;s/\n/, / unless eof'

Replies are listed 'Best First'.
Re^4: Better Way of Manipulating Array Elements
by ikegami (Patriarch) on May 20, 2009 at 00:05 UTC

    You are missing that he want's a blanks after the commas.

    That's not what he said ("join all the elements by a comma"), and that's not what he's currently doing (print join ",", @z;). Trivial change either way.

    I improve (golfwise) to [...] unless eof

    Good, but
    if !eof is even shorter (6 from 10) and clearer.
    if !eof() means something different and might be desirable.

    But since capturing a literal regex is silly

    I doubt the OP is really matching "d".

      print join ", ", map { chomp; s/(d)/new(\1)/ } @a;
      I was just looking at that - but you are right about the blanks - 1:0 for you.

      if !eof is shorter and clearer.
      Damn it you are right again - 2:0 for you.

      *defeated* :-)

      if !eof() means something different and might be desirable
      My previous post was not really meant to be taken seriously - so it's even better that I learn something here - many thanks!