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


in reply to Imperative VS Functional - Imperative wins?

Your comparison does not look very fair. Both codes:

sub 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 ); }
and
sub bar { return map({join(q[::], @$_[0 .. $#$_ - 1]), $$_[$#$_];} [split(/::/ +, shift)]); }
look like very convoluted ways to split a module name into two parts. Maybe something simpler as
sub boo { my $a = shift; if ($a =~ /^(?:(.*)::)?(.*)$/) { return ($1 || '', $2); } }
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.