I have a string something like this
$abc = abc,xyz,{1,2,3,4},18-90-89,{{1,2},{5,6,7,8}},yts
I want to split this into tokens stored in an array(say @elems) such as
$elems[0] = abc
$elems[1] = xyz
$elems[2] = {1,2,3,4}
$elems[3] = 18-90-89
$elems[4] = {{1,2},{5,6,7,8}}
and so on.
The rules are
1."Anything inside a parenthesis is a separate token even though it might contain the general delimiter comma (,)"
2."Nesting of parenthesis is possible"
3."no assumption can be made about the data i.e. it is a general mix of alphanumeric characters"
A friend of mine told that this is beyond the scope of regexp and this is only possible using Parse::RecDescent module as this problem is similar to token parsing by the compiler.
Dear monks, please help me write perl code to achieve this effect either through a regex or by use of any module such as Parse::RecDescent.
Thanks in advance!
Karthik
Edited by Chady -- added formatting
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.