UPDATE:
I've implemented most of the suggestions I received and the little program now looks like this:
#!/usr/bin/perl -w #Purpose: To Take a DOS file wildcard and thus take all the matching c +ustom SGML files in the working directory and subdivide them into new + files whose names are the id's of the divs in those original files. use strict; print "What file(s) do you want to run this program on?\n"; our $lines = ""; our @InFileNames; our @OutFileNames; our @OutFileContent; my $i = 0; my $j = 0; my $TheFile = <STDIN>; chomp ($TheFile); #open file and get all text sub OpenFile { open(FILE, $_[0]) or $lines = ""; local $/ = undef; $lines = <FILE>; #remove blank lines $lines =~ s/\n{2}/\n/gms; close(FILE); } #add ¥ to closing div tags sub MarkClose { $lines =~ s/(<\/div>)/$1¥/gms; } #open output.txt for appending and write results to it sub FileAppend { my $Outfile = ">>" . $_[0] . ".bsd"; my $Content = $_[1]; open(FILE, $Outfile) or die "Can't open $Outfile.\n"; print FILE $Content; print FILE "\n"; close FILE; } #Create an array containing all file in the directory matching the glo +b. sub GetInFileList { my $FileDef = $_[0]; @InFileNames = glob($FileDef); } #Populate an array with the contents of the id attribute of every <div +> tag in the input file. sub GetOutFilesList { my $OutFile; @OutFileNames = $lines =~ m/<div[^>]*>/gms; foreach $OutFile (@OutFileNames){ $OutFile =~ s/<div type=[^\s]* id="([^>]*)">/$1/gms; $OutFile =~ s/\./_/gms; } } #Subdivides the File into the subfiles. sub GetOutFileContent { my $LinesString = $_[0]; @OutFileContent = split /¥/, $LinesString; } ### Does the job &GetInFileList($TheFile); for ($i = 0, $i < @InFileNames, $i++) { &OpenFile($InFileNames[$i]); &MarkClose(); &GetOutFilesList; &GetOutFileContent($lines); for ($j = 0, $j < @OutFileNames, $j++){ &FileAppend($OutFileNames[$j], $OutFileContent[$j]); } } #be nice and say it's done print "Program Finished\n";
The script now dies at a very specific point: On line 13 or possibly 18, where it gives the following error message:
Use of uninitialized value in open at ##program name censored## line 18, <STDIN> line 1.I take this to mean that the array entitled @InFileNames has no contents, because the glob function used to fill it on line 45 didn't behave as I thought it would.
Also, the debug mode behaved oddly when it reached the <STDIN> line, it prompted me for input with the line DB(1), and then prompted me again with DB(2) when I had given it its input, and so on ad infinitum.
In reply to Re: Need help with subdividing SGML files
by DukeLeto
in thread Need help with subdividing SGML files
by DukeLeto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |