#!/usr/bin/perl -w #Purpose: To Take a DOS file wildcard and thus take all the matching custom 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 = ; chomp ($TheFile); #open file and get all text sub OpenFile { open(FILE, $_[0]) or $lines = ""; local $/ = undef; $lines = ; #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 glob. sub GetInFileList { my $FileDef = $_[0]; @InFileNames = glob($FileDef); } #Populate an array with the contents of the id attribute of every
tag in the input file. sub GetOutFilesList { my $OutFile; @OutFileNames = $lines =~ m/]*>/gms; foreach $OutFile (@OutFileNames){ $OutFile =~ s/
/$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";