I have come across a hurdle with some code I am currently writing and seek enlightenment from my fellow monks. I am wanting to set up a
split statement to split a string based on either "
," or "
," - that is
/,\s+/ and
/\,/. I have attempted this with a
split command thus:
- my @array = split(/,(\s+|)/, $string);
The problem with this is that I seem to be getting an additional array field consisting of a single space - That is if $string is this@emailaddress.com, that@emailaddress.com, I have the following returned:
this@emailaddress.com
that@emailaddress.com
This is most obviously an syntax error on my part, but an explanation of my fault to further my understanding would be appreciated much more than an immediate code solution. I can post the full segment of code where I am having this issue if need be, but have trimmed the post to contain only the most relevant information - /msg me if more information is needed.
Many Thanks
Ooohhh, Rob no beer function well without!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.