Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by tilly (Archbishop)
on Nov 26, 2000 at 03:53 UTC ( [id://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...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found