in reply to problems splitting string

As illustrated by some of the answers, you can see that this is where "split" is probably the wrong tool. Don't reach for the wrong tool. In this case, it was easier to talk about what to keep.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: problems splitting string
by Tanktalus (Canon) on Dec 15, 2005 at 19:53 UTC

    For the split bullet, I would actually describe it as "When it's easier to talk about separators" - such as "I want to split on commas" or "I want to separate on colons" or "I want to separate right before each number (not necessarily each digit)".

    If this is how you're thinking of the problem, then split is probably the right tool. However, given the original question, I get the feeling that the problem was being thought of as "what to keep" where using match-global is more in line with the real problem. The OP seems to be asking "How do I do X with Y?" - wanting to match stuff with split.

    If you take away the context of the question, and it were to become "How do I get this string '1 Cat 2 Dogs 3 Hamsters' to become this list ('1 Cat', '2 Dogs', '3 Hamsters')", then I would think either split or match-global would be perfectly legitimate responses.