Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Elegant way to split into sequences of identical chars? (while //g)

by tye (Sage)
on Nov 29, 2005 at 21:01 UTC ( #512769=note: print w/replies, xml ) Need Help??


in reply to Elegant way to split into sequences of identical chars?

sub splitSameChars { for( shift @_ ) { push @_, $1 while /((.)\2*)/g; } @_; }

- tye        

  • Comment on Re: Elegant way to split into sequences of identical chars? (while //g)
  • Download Code

Replies are listed 'Best First'.
Re^2: Elegant way to split into sequences of identical chars? (while //g)
by tphyahoo (Vicar) on Nov 30, 2005 at 15:16 UTC
    For me, easier to understand written so:
    use strict; use warnings; use Data::Dumper; print join " ", splitSameChars('xx556xx'); sub splitSameChars { my $letters = shift; push @_, $1 while $letters =~ /((.)\2*)/g; @_; }
    (The for loop confused me.)
      (The for loop confused me.)

      Ah, but it wasn't a for loop. It was a for aliasing. This can be a very useful technique, so you might want to get used to it. Granted, in this case, it was done to try to better meet the original request for 'an "elegant" 1-liner', and isn't the way I would usually write code (and not even the way I originally posted the code, before I noticed the quoted part of the original request).

      - tye        

        Thanks, but what is that exactly? Google and supersearch weren't much help.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2019-06-19 08:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Is there a future for codeless software?



    Results (87 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!