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


in reply to Re^4: Elegant way to split into sequences of identical chars? (for)
in thread Elegant way to split into sequences of identical chars?

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