Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re (tilly) 3: Apparent Inconsistencies in Perl Function Naming

by tilly (Archbishop)
on Nov 26, 2000 at 03:53 UTC ( #43331=note: print w/ replies, xml ) Need Help??


in reply to Re: Re: Apparent Inconsistencies in Perl Function Naming
in thread Apparent Inconsistencies in Perl Function Naming

I like that book analogy!

My preference would be to check my context. If a list made sense I would return a list of the number of letters on each page. If it didn't I would add up the number of letters on each page, then add those up. So my previous piece of code becomes this:

sub length { if (1 == @_) { return CORE::length(shift); } else { my @lengths = map {CORE::length($_)} @_; if (wantarray) { return @lengths; } else { my $tot = 0; $tot += $_ foreach @lengths; return $tot; } } }
Note how this falls naturally out of length being the length of a string, and thinking of Perl as being list-oriented...


Comment on Re (tilly) 3: Apparent Inconsistencies in Perl Function Naming
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-09-23 21:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls