http://www.perlmonks.org?node_id=632035


in reply to Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)

If you don't mind the different order of the output then:
$ perl -le'print for keys %{ { "ZBBBCZZ" =~ /((.)\2*)/g } }' Z ZZ BBB C
  :-)

Replies are listed 'Best First'.
Re^2: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
by jdporter (Paladin) on Aug 12, 2007 at 13:22 UTC

    Excellent excellent excellent.
    A solution to the order problem would be to use an order-remembering hash (e.g. Tie::IxHash). Or you could pluck out the even-numbered elements of the list, e.g.

    $_ = 'abbbccddde'; @a = /((.)\2*)/g; @a = @a[ grep { not $_ & 1 } 0 .. $#a ];
    A word spoken in Mind will reach its own level, in the objective world, by its own weight
Re^2: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
by graff (Chancellor) on Aug 12, 2007 at 14:24 UTC
    If you don't mind the different order of the output...

    ... and also don't mind the possible loss of some intended output:

    # OP's solution, given a different input: $ perl -le'print $1 while "ZBBBCZZCZ" =~ /((.)\2*)/g' Z BBB C ZZ C Z # jwkrahn's solution for that input: $ perl -le'print for keys %{{"ZBBBCZZCZ" =~ /((.)\2*)/g}}' Z ZZ BBB C
    (Not to mention that the OP approach wins at golfing. :)
Re^2: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
by blazar (Canon) on Aug 13, 2007 at 10:06 UTC
    If you don't mind the different order of the output then:

    Sorry if I miss something, but your solution based on a hash, like all hash based ones seems aimed at uniqueness... but that doesn't seem a requirement as of the root node...