Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
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??


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
  :-)


Comment on Re: Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
Select or Download Code
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...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://632035]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (12)
As of 2014-07-29 17:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (225 votes), past polls