tchrist@convex.COM (Tom Christiansen) (02/03/91)
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 <tchrist@convex.com>)