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]/;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Nifty qr OR bullets with butterfly wings
by ikegami (Patriarch) on Aug 13, 2009 at 19:24 UTC | |
by belg4mit (Prior) on Aug 13, 2009 at 20:00 UTC | |
by ikegami (Patriarch) on Aug 14, 2009 at 02:59 UTC | |
by belg4mit (Prior) on Aug 14, 2009 at 03:37 UTC |
Back to
Cool Uses for Perl