I am convinced once again that bugs exist for a larger reason than simply because we all make mistakes. You see, bugs exist so that we will write patches and patches exist to remind us of the classical greek lesson of hubris. In a nutshell, the gods punish those of us who are guilty of “over-weaning pride” by insuring that any code we publish as a 'fix' will shortly there after be shown to have problems of its own. A case in point, my efforts to debug Pod2Html!

I ran into yet another problem with html.pm and had to take a bit of sledge-hammer to our friend 'clean_data'. At any rate, the new version looks like:

# # coalesce: concatenate paragraphs that should be contiguous # sub coalesce { # hsm 10/11/01 my $array = shift; # hsm 10/11/01 my $i = shift; # hsm 10/11/01 my $n = $#{$array}; # hsm 10/11/01 ${$array}[$i++] .= ${$array}[$i]; # hsm 10/11/01 splice(@{$array},$i,1,@{$array}[($i + 1)..$n--]); # hsm 10/11/01 $#{$array} = $n; # hsm 10/11/01 } # hsm 10/11/01 # # clean_data: global clean-up of pod data # sub clean_data($) { my ($dataref) = @_; my $i; for ( $i = 0 ; $i <= $#$dataref ; $i++ ) { if (${$dataref}[$i] =~ /^=begin html/i) { # hsm 10/11/01 while (${$dataref}[$i + 1] !~ /^=end html/i) { # hsm 10/11 +/01 coalesce($dataref,$i); # hsm 10/11/01 } # hsm 10/11/01 } # hsm 10/11/01 if(${$dataref}[$i] =~ s/([^\x0a])\x0a=/$1\x00=/g) { # hsm 10/9 +/01 my @otherchunks = split ( /\x00/m,${$dataref}[$i]); # hsm +10/9/01 splice( @$dataref, $i, 1, @otherchunks ); # hsm 10/9/01 redo; # hsm 10/9/01 } # hsm 10/9/01 ${$dataref}[$i] =~ s/\s+\Z//; # have a look for all-space lines if (${$dataref}[$i] =~ /^\s+$/m and ${$dataref}[$i] !~ /^\s/ ) + { my @chunks = split ( /^\s+$/m, ${$dataref}[$i] ); splice( @$dataref, $i, 1, @chunks ); } } }

Still no particular magic, unless slight-of-hand counts<g>! The second problem was the loss of "\n\n" lines within <larger>=begin html/=end html</larger> commands. This is caused by the notion that the POD paragraph definitions hold within what amounts to an html block. It seems to me that you are far safer parsing this as an unbreakable unit of text, stopping only when you run into the next <larger>=end html</larger> marker. This implementation is naive in that I don't allow arbitrarily nested = commands within the html text. It begins to look like this might well require a major re-write, something that doesn't make much sense given the existence of Pod::Parser. I'm going to think about it some more before I figure out which way to go.

hsm

<smaller>whose handle in prep school was—you guessed it! Hubris</smaller>


In reply to Bugs, Patches and Hubris by hsmyers

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.