Read the comments. Don't ask me to explain what the code does. I know what it used to do before I chiseled away at it in a failed attempt to isolate the bug (in Perl, I assume), and that is proprietary information. The only thing I know is that the output makes sense if you change $Build_Text .= $New_Line.'<br>';(near the bottom) to $Build_Text .= $New_Line;
#!/usr/bin/perl -w ###################################################################### +######## print "Content-type: text/html\n\n"; $Count_Link = 14; @line = ('<a href = "http://polisource.com">12(2345678901234)</a>'); for($Link_Count=0;$Link_Count<scalar(@line);$Link_Count++) { $line[$Link_Count] =~ /href.+?>(.*?)</; $Text = $1; if(length($Text) <= $Count_Link) { $line[$Link_Count] =~s /(href.+?>)(.*?<)/$1$Build_Text$2/; $Build_Text = ""; next; } $Width2 = $Count_Link-1; $Order = substr($Text,0,$Count_Link); if($Order !~ /\(/) { $Build_Text .= $Order . '<br>'; $line[$Link_Count] =~s /(href.+?>)\Q$Order\E/$1/; $Link_Count--; if (substr ($Text,$Count_Link,1) ne ' ') { if (!$Links_Count) { chomp($ORIGINAL_DOC = "$OriginalLinks[$OL_count]"); $Links_Count .= " $ORIGINAL_DOC:\n"; } $Links_Count .= "$Order"; next; } } for($Break_Count = $Width2;$Break_Count>-1;$Break_Count--) { $character = substr($Order,$Break_Count,1); $c2 = ')'; if ($character eq '[') { $c2 = ']'; } ################################### ### "test 1" gets printed. if (!$Break_Count){ print "<br>test 1"; } ################################### if ((!$Break_Count)&& ($Build_Text =~ /.*?(?!<br>.*<br>)(.*)(<br>)/)&& (length $1 < $Count_Link)&& ($line[$Link_Count] =~ /href.+?>$Order($c2|.$c2)/)) { ###################################################### ### If the above condition were true, "test 2" would be printed. Since + it's not printed, this block is skipped. if (!$Break_Count){ print "<br>test 2"; } ###################################################### $New_Line = substr($Order,1); $line[$Link_Count] =~s /(href.+?>).{$Count_Link}(.)/$1/ +; $Build_Text =~s /<br>$/$character<br>$New_Line$2<br>/; $Link_Count--; last; } elsif (!$Break_Count) { ################################### ### Nothing changed since "test 1" ### was printed, so why isn't ### "test 3" printed? if (!$Break_Count){ print "<br>test 3"; } ################################### $Build_Text .= $Order . '<br>'; $line[$Link_Count] =~s /(href.+?>)\Q$Order\E/$1/; $Link_Count--; last; } elsif ($character eq '(') { $New_Line = substr($Order,0,$Break_Count); $Build_Text .= $New_Line.'<br>'; $line[$Link_Count] =~s /(href.+?>)\Q$New_Line\E/$1/is; $Link_Count--; last; } } }

update (broquaint): title change (was Why?)


In reply to Strange problems with CGI script by Wassercrats

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.