Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Here at plasmasturm I see the following little sub:
sub strip { s/\A\s+//, s/\s+\z// for my @r = @_; @r }
Formatting that out a bit, it's:
sub strip { s/\A\s+//, s/\s+\z// for my @r = @_; @r }
So, I suppose it's stripping whitespace off of every element in @_. I see what the regexen are doing, but how is that "for" loop working? With the equals sign there ... I just don't get it. Regarding the comma, I suppose it's just a separator that tells perl to just evaluate one s/// after the other.
Further down in the code, there's this "for" loop:
for ( 1 .. 3 ) { run_fork { child { # [snip] some stuff ... exit; } } }
Are run_fork and child function calls? They look strange to me. The only place I think I've ever seen functions that take a block of code after them is with map and grep... How does one write a sub that takes a block of code (in curlies) like that?
Actually, I've used {}'s to make hash refs for passing a handful of named params to a sub, but I don't think that's what's going on here...
|
---|