in reply to Re^2: Elegant way to split into sequences of identical chars? (while //g)
in thread Elegant way to split into sequences of identical chars?

(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        

  • Comment on Re^3: Elegant way to split into sequences of identical chars? (for)

Replies are listed 'Best First'.
Re^4: Elegant way to split into sequences of identical chars? (for)
by tphyahoo (Vicar) on Nov 30, 2005 at 16:01 UTC
    Thanks, but what is that exactly? Google and supersearch weren't much help.

      for can be used to loop over a list of items (in which case it makes more sense to use foreach except that Perl programmers are usually too interested in being terse). It can be used to construct a C-style loop, for(init;whileTrue;gotoNext). It can also be used to create a temporary alias to some scalar that you want to do more than one operation on.

      for( $thingy{foo()}{bar()} ) { s/^\s+//; s/\s+(#.*)?$//; tr/A-Z/a-z/; }

      vs.

      $thingy{foo()}{bar()} =~ s/^\s+//; $thingy{foo()}{bar()} =~ s/\s+(#.*)?$//; $thingy{foo()}{bar()} =~ tr/A-Z/a-z/;

      - tye