Maze has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Formatting The Communist Manifesto
by bart (Canon) on Apr 06, 2007 at 16:55 UTC | |
|
Re: Formatting The Communist Manifesto
by Maze (Sexton) on Apr 06, 2007 at 16:46 UTC | |
by bart (Canon) on Apr 06, 2007 at 16:56 UTC | |
by jonadab (Parson) on Apr 06, 2007 at 20:37 UTC | |
|
Re: Formatting The Communist Manifesto
by talexb (Chancellor) on Apr 06, 2007 at 16:35 UTC |