Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
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...

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://43331]
help
Chatterbox?
[stevieb]: cheers beech. twas totally my mistake, and I got bit. When things work for so long without issue, one becomes complacent (ie. replace we/one with I ;) I've been copy/pasting that around for a few years without a hiccup, so when...
[stevieb]: choroba pointed that out, I was just, you know, *sigh*. In effect, I was lucky and fortunate

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2017-07-25 23:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (383 votes). Check out past polls.