How come the following script:

#!/usr/bin/perl use strict; use warnings; if (defined $ARGV[0]){ open SOURCE, $ARGV[0] or die("$!"); } else{ print "please tell me a file to covert..." and die; } print '<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE article PUBLIC +"-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbo +ok/xml/4.1.2/docbookx.dtd\">'; print "\n\n"; my $marker = 0; my $isheader = 0; my $isbreak = 0; my $paranumber; my $articlename; my $line; my $char; $char = getc(SOURCE); while ($char ne "\n"){ track($char); if (defined $articlename){ $articlename = "${articlename}$char"; } else{ $articlename = $char; } $char = getc(SOURCE); } $articlename = "${articlename}$char" if defined $articlename; print "<article> <title>$articlename</title>"; print "<chapter>"; getc(SOURCE); while($char = getc(SOURCE)){ if($char eq "\n" and $marker == 1 and $isbreak == 0){ track("found break"); writeXMLelement($line,$isheader); $line = $char; $isbreak = 1; $isheader = 0; $paranumber++; } elsif($char eq "\n" and $marker == 2 and $isheader == 0){ track("found header"); $isbreak = 0; $isheader = 1; } elsif($char eq "\n"){ $isbreak = 0; track("found newline"); $marker++; $line = "$line " unless (!defined $line); } elsif($char =~ /[\w\s\d\.\,\:\;\"\'\?\!\0]/){ $isbreak = 0; #track("found text"); $marker = 0; if (defined $line){ $line = "${line}$char"; } else{ $line = $char; } } else{ $isbreak = 0; track("text not found"); $marker++; $line = "$line " unless (!defined $line); } } sub writeXMLelement{ my $element = $_[0]; chomp $element; $element = reverse $element; chomp $element; $element = reverse $element; if ($_[1] == 0){ print "\n<para>\n$element\n</para>\n"; } elsif ($_[1] == 1){ print "</chapter>"; print "\n<chapter id=\"$element\">\n"; print "<title>$element</title>\n"; } } sub track{ warn "\ntrack:$_[0] at $paranumber\n"; } print "\n</chapter>"; print "\n</article>";

finishes when it reaches the following paragraph in the communist manifesto:

10. Free education for all children in public schools.

    Abolition of children's factory labour in its present form.

    Combination of education with industrial production, &c., &c.

this is not the only example of something which causes my script to baulk, and I'm stumped, anything to do with the reading process because I can only guess that my while loop isn't being satisfied


In reply to Formatting The Communist Manifesto by Maze

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.