Although your code might be a bit clearer to read, as a few other posts say, the functionality is not the same. Given this code:
my $str = "Line 1 has text, but next is an empty line:\r\n\r\nThird li +ne has text\r\n"; print "Original String:\n'$str'\n\n"; print "Ovid:\n", Ovid_Clear_MakePtag($str), "\n\n"; print "mandog:\n", MakePtag($str), "\n"; sub Ovid_Clear_MakePtag{ my $fixme = shift; # take in our parameters return join "\r\n", # join with newlines map { "<p>$_</p>" } # wrap each line in <p></p> tags grep { /\S/ } # must have at least one non-whitespace + character split "\r\n", $fixme; # break apart on the newlines } sub MakePtag{ chomp(my $fixme = shift); # take in our parameters $fixme=~s|(\r\n)|</p><p>|g; # replace all \r\n with <\p><p> $fixme = "<p>$fixme</p>"; # Add beginning and ending tags return $fixme; }
The following results are produced:
Original String: 'Line 1 has text, but next is an empty line: Third line has text ' Ovid: <p>Line 1 has text, but next is an empty line:</p> <p>Third line has text</p> mandog: </p>ine 1 has text, but next is an empty line:</p><p></p><p>Third line + has text

--Jim


In reply to Re: What is clear code ? by jlongino
in thread What is clear code ? by mandog

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.