From: Brian Candler Date: 2004-10-10T19:42:11+09:00 Subject: Re: split with negative limit On Sun, Oct 10, 2004 at 01:18:48PM +0900, trans. (T. Onoma) wrote: > Word o' warning. I just put this comment in a program: > > lines = self.split("\n",-1) # boy oh boy was that -1 a pain to figure out! > > All told I probably wasted half of my day trying to figure this out because it > was causing another part of the program to act oddly (which I still don't > quite get but nonetheless), thus digusing the real issue. > > This is VERY unintuitive. It's taken from Perl. See 'man perlfunc': split /PATTERN/,EXPR,LIMIT ... If LIMIT is specified and positive, splits into no more than that many fields (though it may split into fewer). If LIMIT is unspecified or zero, trailing null fields are stripped (which potential users of "pop" would do well to remember). If LIMIT is negative, it is treated as if an arbitrarily large LIMIT had been specified. Perhaps in the early days, Ruby being similar to Perl was considered a good thing :-) Regards, Brian.