$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
translates the %20 and whatnot of HTML encoding into the correct characters. This is done the with the help of the magic /e modifier ( see the library and search on egimosx for a full discussion ), which causes perl to run the REPLACEMENT part through an eval first. In this case, the pack statement is translating the 20, eg, into a space.

The line giving you fits is the second one, which is replacing all newlines with 20 spaces. And yes, there is something you can do about it :).
Try this instead:

$sub_body =~ s/\n/<BR>/g;
which does exactly what you asked - substitutes
tags for every newline

I am curious to know why they used the /i modifier on the regex, though. To the best of my knowledge, newlines do not come in upper- and lower- case flavours.

Mik
Mik Firestone ( perlus bigotus maximus )

UPDATE Sorry - I badly misparsed the regex. Don't ask why because I couldn't tell you for certain. It is replacing it with, as btrott so correctly stated, a single space.
mea culpa,
Mik


In reply to Re: form parsing by mikfire
in thread form parsing, hex, HTML formatting by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.