Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!olivea!uunet!bywater!arnor!arnor!victor From: victor@watson.ibm.com (Victor Miller) Newsgroups: comp.lang.perl Subject: Question about split Message-ID: Date: 28 May 91 21:11:38 GMT Sender: news@watson.ibm.com (NNTP News Poster) Reply-To: victor@watson.ibm.com Organization: IBM, T.J. Watson Research Center Lines: 36 Nntp-Posting-Host: irt I'm a little confused about perl's behavior in split. If you run (on 4.003) then code below #!/usr/local/bin/perl #Test how certain patterns split sub test { ($a) = @_; @a = split(/:/,$a); print "split('$a')=(",join(',',@a),") count=",scalar(@a),"\n"; } &test('a:b:c: '); &test('a:b:c:'); &test('a:b:c'); #end of program You get the results: split('a:b:c: ')=(a,b,c, ) count=4 split('a:b:c:')=(a,b,c) count=3 split('a:b:c')=(a,b,c) count=3 Which I find a little counter-intuitive: I thought that perl should distinguish between the second and third cases. I would have thought that the output of the second case should have been split('a:b:c:')=(a,b,c,) count=4 Why is it done the way that it is? -- Victor S. Miller Vnet and Bitnet: VICTOR at WATSON Internet: victor@watson.ibm.com IBM, TJ Watson Research Center