Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

RE: Re: ASCII to HTML

by chromatic (Archbishop)
on Apr 05, 2000 at 02:12 UTC ( [id://6888]=note: print w/replies, xml ) Need Help??


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.)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://6888]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (1)
As of 2024-04-25 00:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found