Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!ccu.umanitoba.ca!rahardj From: rahardj@ccu.umanitoba.ca (Budi Rahardjo) Newsgroups: comp.lang.perl Subject: Re: Question about split Summary: I am also confused ... Keywords: split Message-ID: <1991May29.163413.17294@ccu.umanitoba.ca> Date: 29 May 91 16:34:13 GMT References: Followup-To: comp.lang.perl Organization: University of Manitoba, Winnipeg, Canada Lines: 42 victor@watson.ibm.com writes: : 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 Replace @a = split(/:/,$a); with @a = split(/:/,$a,10); You will get split('a:b:c: ')=(a,b,c, ) count=4 split('a:b:c:')=(a,b,c,) count=4 split('a:b:c')=(a,b,c) count=3 : Why is it done the way that it is? I don't know ... This is a problem that I have (similar to yours : #!/usr/local/bin/perl $pat2='a:b::::::::::::::x::::::::::::::::::::::::::::::::::'; # contains 50 : @res = split(/:/,$pat2); print "splitted (" . scalar(@res) . ")\n"; @res = split(/:/,$pat2,100); print "splitted (" . scalar(@res) . ")\n"; # end of program The second split (the one with '100') produce the result that I wanted (an array of 50 entries)... -- budi