XP is just a number PerlMonks

### Re: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)

by jwkrahn (Monsignor)
 on Aug 12, 2007 at 08:48 UTC ( #632035=note: print w/replies, xml ) Need Help??

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 (Canon) 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...

Create A New User
Node Status?
node history
Node Type: note [id://632035]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (8)
As of 2017-06-25 08:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (565 votes). Check out past polls.