in reply to Imperative VS Functional - Imperative wins?
Your comparison does not look very fair. Both codes:
andsub foo { my @tokens = split /\:\:/, shift; return ( q[], $tokens[0] ) if scalar( @tokens ) == 1; return ( $tokens[0], $tokens[1] ) if scalar( @tokens ) == 2; my $function = pop @tokens; return ( join( q[::], @tokens), $function ); }
look like very convoluted ways to split a module name into two parts. Maybe something simpler assub bar { return map({join(q[::], @$_[0 .. $#$_ - 1]), $$_[$#$_];} [split(/::/ +, shift)]); }
would work too. Using map for a 1-element array does not seem very efficient. Deconstructing a string with split to get it together with join does not seem optimal as well.sub boo { my $a = shift; if ($a =~ /^(?:(.*)::)?(.*)$/) { return ($1 || '', $2); } }
In Section
Seekers of Perl Wisdom