While searching for a parse of ASCII bulleted lists the other day, I ended up rolling my own:
while( $text =~ /\G\s*($bullet)\s*([^\n]+)((?:\s*$bullet{2,}\s*[^\n]+)+)?/g ){ ...}
And stumbled across what I believed to be a clever use of
qr to create $bullet from a separate data structure (which permits us to later determine what style of bullet we had, and map it to something):
%bullets = ('*'=>'foo', '+'=>'bar', '@'=>'qux');
#Original, which as ikegami points out, doesn't quite work
#my $bullet= sprintf(qr/[%s]/, join('', keys %bullets));
#Alternate form, that I was trying to make more scrutable, with added
+\Q
my $bullet= qr/[\Q@{[join '', keys %bullets]}\E]/;
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.