Just another Perl shrine | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
G'day swampyankee, "I was expecting ... "SMITH", "-", "JONES" ... I got "S","","M","", ... What did I do wrong?" The documentation for split describes what happens with capturing. The section at the end (starting with "If the PATTERN contains capturing groups, ...") has a description followed by several examples. Here's your regex without capturing:
Now with capturing (and what I think you intended):
If you coded /(-|)/ instead of /(-| )/, you would get the output you're seeing:
That, of course, is just a guess; however, given other issues (already noted by hippo) in your posted code, possibly a good guess. "The split's documentation seems to say that / / doesn't split between every character, but " " does." I expect you've misread or misunderstood something. Had you quoted the text that you thought seems to say what you suggest, I could comment further. There can be errors in documentation and those errors can be fixed; perhaps there's not an error but a clarification of the current text would help — obviously, the source of the confusion needs to be identified as a first step. Anyway, neither / / nor " " will "split between every character":
Without the spaces, both will "split between every character":
Regardless, I don't see how / / or " " relate to /(-| )/. — Ken In reply to Re: Split confusion
by kcott
|
|