
alalleyn
Novice
Apr 2, 2002, 12:44 AM
Post #1 of 3
(331 views)
|
|
Outputting to file information between <tag> and </tag>
|
Can't Post
|
|
Hi, Don't know if I am writing to the correct place but might someone be able to help me? If I have the following input file. <section> <title> Main Coding Section </title> <para> The system works by allowing the programmer to split a program up into a number of small scraps that can appear in any order within the file. Then one of the pocesses reorders them and outputs them to a specified file while the other process just copies the enitre file with all the document but with the markup removed. </para> <para> Scraps always contain certain information file the file that it is to be written to and a name. In the following section I will be starting a new Java file. </para> <programlisting id="scrap1" role="Welcome.java"> -- This is sample code for Java using the basic program Hello World -- Any other comments on might feel important like authour and date of last modification. public class Welcome { </programlisting> <para> The next section simply follows on from the first, but in the real program this does not always have to be so. </para> <programlisting id="scrap2" role="Welcome.java"> public static void main ( String args[] ) { <xref endterm="scrap4" /> </programlisting> <para> Now the program must be closed. </para> <programlisting id="scrap3" role="Welcome.java"> } // closes main arguement } // closes entire class </prgoramlisitng> <para> This section of code should appear where the xref element tells it too. Its th main body of code and simply outputs a single like of text. </para> <programlisting id="scrap4" role="Welcome.java"> System.out.println("Welcome to my new system. Reading this file means that all works correctly"); </programlisting> </section> I am trying to get the sections enclosed by the programlisting tags to output to a file called Welcome.java, I would also like to if possible be able to reorder the file at the same time. For instance it would normally output the programlistings in the order that it gets to them. However if it reaches an xref it them outputs that scrap there, before continuing in order again. I have tried to write the following Perl code for outputting in order, but even this seems not to work for me. open (TXT, "<litprog.xml"); while (<TXT>) { @alllines = $_; } $codestarts = 0; $codeends = 0; @currentlist; @biglist; foreach $test (@allines) { if ($test =~ /<\/progamlisting>/) { $codestarts = 0; $codesends = 1; } elsif ($codeends == 1) { foreach $test (@currentlist){ $currentlist = ($currentlist. $test); } push @biglist, $currentlist; $currentlist =(); @currentlist = @_; $endcode = 0; } if ($test =~ /<progamlisting.*>/) { $codestarts = 1; } elsif ($codestarts ==1) { push @currentlist, $test; } close (TXT); open(OUT, ">Welcome.java"); foreach $line (@currentlist){ print "$line \n" } close(OUT) I know it does not work because I have been using the DzSoft Perl editor and it tells tell that execution was aborted due to compilation errors, but I can not see where I am going wrong. Please help if it is at all possible. Thanking you in advance for any help that is offered.
|