Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Imperative VS Functional - Imperative wins?

by ferreira (Chaplain)
on Mar 23, 2007 at 19:07 UTC ( #606328=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://606328]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2019-10-17 02:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?