in reply to Removing recurring consecutive element

Hmmm... Sure you want to delete consecutive same elements? To me it seems you want the first word of each string.

If so what about:

my @str = map{ (split ' ', $_, 2)[0] } @{$tpl} ;

instead of your grep-line

This way you get the first element of each of your strings.


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^2: Removing recurring consecutive element
by neversaint (Deacon) on Oct 13, 2005 at 07:13 UTC
    To me it seems you want the first word of each string.
    No Skeeve. That's not what I want. Instead of this:
    $VAR1 = ['A','B','C','A'];
    I am looking for this:
    $VAR1 = ['A','B','C','A','B'];
    So you can see. For the last array I want to keep the 'last word', which is B. I hope that's clearer for you now.

    ---
    neversaint and everlastingly indebted.......
      If that's what you want. Add this one line after Skeeve's.
      push @str, (split ' ',$tpl->[-1])[2];
      Sorry I still don't know if this implementation gives the fastest running time.

      Regards,
      Edward