develooper Front page | perl.perl6.language | Postings from September 2008

Re: Split with negative limits, and other weirdnesses

Thread Previous | Thread Next
From:
TSa
Date:
September 23, 2008 07:39
Subject:
Re: Split with negative limits, and other weirdnesses
Message ID:
48D8FF7E.8010107@vts-systems.de
HaloO,

Moritz Lenz wrote:
> In Perl 5 a negative limit means "unlimited", which we don't have to do
> because we have the Whatever star.

I like the notion of negative numbers as the other end of infinity.
Where infinity here is the length of the split list which can be
infinite if split is called on a file handle. So a negative number
could be the number of splits to skip from the front of the list.
And limits of the form '*-5' would deliver the five last splits.


> A limit of 0 is basically ignored.
> 
> Here are a few solution I could think of
>  1) A limit of 0 returns the empty list (you want zero items, you get them)

I think this is a nice degenerate case.

>  2) A limit of 0 fail()s

This is a bit too drastic.

>  3) non-positive $limit arguments are rejected by the signature (Int
> where { $_ > 0 })

I think that documents and enforces the common case best. But I would
include zero and use a name like UInt that has other uses as well. Are
there pragmas that turn signature failures into undef return values?


Regards, TSa.
-- 

"The unavoidable price of reliability is simplicity" -- C.A.R. Hoare
"Simplicity does not precede complexity, but follows it." -- A.J. Perlis
1 + 2 + 3 + 4 + ... = -1/12  -- Srinivasa Ramanujan

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About