in reply to delete space

$ perl -we ' print "--$_--\n" for grep $_, split /[ ,]+/, " c1, c2, s1, s2, c3 "; ' --c1-- --c2-- --s1-- --s2-- --c3--
Split on [ ,]+ so that split eats the spaces as well as the commas. The grep eliminates the first empty ("") element.

Replies are listed 'Best First'.
Re^2: delete space
by ikegami (Patriarch) on Nov 30, 2009 at 15:57 UTC
    That will cause "c1, c2a c2b, c3" to return four elements instead of three.
    split /, /
    or
    split /\s*,\s*/
    is more appropriate.
Re^2: delete space
by zeni (Beadle) on Dec 01, 2009 at 07:52 UTC

    s/\s+//g

    This solved the problem. thanks all