in reply to Re: ASCII to HTML
in thread ASCII to HTML

Whoa! That second regex will Do Weird Things after the first. (It picks up the newlines after the fresh

tag). Here's another approach:

my $str = TEXT; Foo is on this line, and bar is in this paragraph. Baz is in a new paragraph. TEXT my @para = split(/\n\n/, $str); s!\n!<br>\n! foreach @para; $str = join "\n<p>\n", @para; print ">>$str<<\n";
For extra credit, put that in a one-liner. *sigh*

Replies are listed 'Best First'.
RE: RE: Re: ASCII to HTML
by btrott (Parson) on Apr 05, 2000 at 02:53 UTC
    Oops oops oops. Thanks for catching that--I guess I must not always use that regex. :)

    But here's your one-liner:

    $str = join "\n<p>\n", grep s/\n/<br>\n/g || 1, split /\n\n/, $str;
    (The "|| 1" in there makes it so that even paragraphs that don't contain any carriage returns inside of them, and thus don't match in the substitution, still get included in the final list of paragraphs.)