in reply to Re: AutoMagic HTML
in thread AutoMagic HTML

> which is best?

Best is what YOU think is best. TMTOWTDI and no one can tell what's the best way if you don't define "best" ;-)
Is best the code that is

Having said that, I would do it on a line-by-line basis, something like this

while (<>) { # replace italics and bold s{^([ib])\s+(.*)}[<$1>$2</$1>]; # find ordered lists if (my $hit= /^\[\s*$/ .. /^\]\s*$/) { if ($hit==1) { print "<ol>\n"; next; } if ($hit=~ /e0/i) { print "</ol>\n"; next; } s[^][<li>]; s[$][</li>]; } }
This won't work with cascaded, ordered lists, but it's a starting point.

Replies are listed 'Best First'.
Re: Re: Re: AutoMagic HTML
by Cody Pendant (Prior) on Jun 24, 2003 at 07:02 UTC
    * fastest * shortest * least memory consuming

    Sorry, good point, I meant "fastest", as this rendering is supposed to happen on the fly as HTML is output to the browser.



    “Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
    M-J D
      Trying it a few different ways and testing it out with Benchmark is the best way to know for sure.

      My intuition is that you'll go faster with smaller "bites", since you'll be slinging less data around, so I would suspect that reading it in a line at a time, then using a special sub or state when you need multiline input, would be fastest. But that's just a guess...