in reply to How does this code work? (from "Perl is Unix")

regarding
sub strip { s/\A\s+//, s/\s+\z// for my @r = @_; @r }
The for is acting on @_ which in perl is 'the array i'm currently looking at' and in this scope is the list you passed to strip. ugly code though.

for the other use Proc::Fork; is probably of interest

see http://search.cpan.org/~aristotle/Proc-Fork-0.71/lib/Proc/Fork.pm
run_fork -creates a fork for the block
child - declares the block to run with a child

Replies are listed 'Best First'.
Re^2: How does this code work? (from "Perl is Unix")
by Anonymous Monk on Nov 06, 2009 at 06:21 UTC

    I'm not concerned with forking code here, per se. What I'd just like to know is, what does something like

    foo { bar { ... } baz { ... } }

    even mean? I know what $, @, %, and & signify, and I know what sub {...} gets me, but it's just completely flying over my head what I'm looking at here with these barewords followed by code in curlies. Am I missing something obvious? :)

Re^2: How does this code work? (from "Perl is Unix")
by Aristotle (Chancellor) on Nov 07, 2009 at 03:18 UTC

    I didn’t aim for clarity in that bit. I wanted to waste the least space possible on code to perform this function, because I was contrasting with Ruby and Python examples, where there is no need to write any code for this because both languages include strip methods in their built in String classes.

    Maybe I should lobby for the inclusion of a strip function in Scalar::Util. (It could even be written in XS, and therefore go faster than regexes. Hmm. There’s a thought.)

    Makeshifts last the longest.

      Is it just me or does the whole bunch of Utils modules seem very haphazard, from namespace choices to grouping