Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!bcm!convex!news From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: combined split modes? Message-ID: <1991Feb02.190414.10121@convex.com> Date: 2 Feb 91 19:04:14 GMT References: <1991Feb2.180528.13014@uvaarpa.Virginia.EDU> Sender: news@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 25 Nntp-Posting-Host: pixel.convex.com From the keyboard of eichin@athena.mit.edu: :1) split(/[ \t]+/,"a-b c") yields ("a-b","c") :2) split(/[ \t]/, "a-b c") yields ("a-b","","","","","c") :3) split(/(-)/, "a-b c") yields ("a","-","b c") : :What I want is something that yields ("a","-","b","c"). :I'm sure I can do a nested foreach, splitting with the first pattern :and then splitting each result with the third. But I though I might :perhaps be able to do it with a single split... : :4) split(/(-)|[ \t]/,"a-b c") yields ("a","-","b","","","","","c") :5) split(/(-)|[ \t]+/,"a-b c") yields ("a","-","b","","c") I think for expediency (read laziness), I'd just use your method #5 and send it through a grep that weeds out null elements: @a = grep($_ ne '', split(/(-)|[ \t]+/,"a-b c")); There are probably many other ways. --tom -- "Hey, did you hear Stallman has replaced /vmunix with /vmunix.el? Now he can finally have the whole O/S built-in to his editor like he always wanted!" --me (Tom Christiansen )