Output redirection and output to a file 
Author Message
 Output redirection and output to a file

It's me again : - )

I am trying to create a main FAQ page from a text file (database
dump).  The script below does that properly, however, I would like to
create the sub pages at the same time.  I run this script with
"./script input.txt >mainfaq.html".  The main page will just have the
catagory and question with a link (and bookmark) to a subpage that has
all the questions and answers for a catagory.  The stuff that I would
like on the sub page has been double commented (##) below. (I wasn't
sure of the syntax, but you get the idea)  The filename of the sub
page is set by $file depending on the catagory, and the sub pages will
be created everytime.

I'm still new at this and I do have the Programming perl book from ORA
so send me some page references.

Thanks

C-ya

Scott

#!/usr/bin/perl
#This perl program takes a formated input pipe and converts it to a
#html document with the appropriate links

######################
#       Written By:   Duane R. Ellison

######################
#       Rewritten By:  Scott D. Gregory

######################
#       Define main variables

        $did_head = "no";             # generated head of document
        $do_end  = "no";              # generated end of document
        $cat_check = "empty"; # set initial catagory variable

######################
#       Generate the head of the html document
#       set $did_head to 0 (open) so it doesn't run this again

sub do_head {
        print "<html>\n";
        print "<head>\n";
        print "<title>Publishing Library FAQ</title>\n";
        print "</head>\n";
        print "<body>\n";
        print "<center>\n";
        print "<h1>Publishing Library<br>\n";
        print "Frequently Asked Questions</h1>\n";
        print "Please CLICK on question to view the answer.\n";
        print "</center>\n";
        print "<p><br>\n\n";

        $did_head = "yes";

Quote:
} # end of do_head

###############################
#       Catagory subroutine 1
#

sub initial_cat {
        $counter = 1;
        print "</ol>\n";
        print "<h3>$type</h3>\n";
        print "<ol>\n";

##      print "<html>\n" >$file;
##      print "<head>\n" >>$file;
##      print "<title> Publishing Library FAQ</title>\n" >>$file;
##      print "</head>\n" >>$file;
##      print "<body>\n" >>$file;
##      print "<center>\n" >>$file;
##      print "<h1>Publishing Library<br>\n" >>$file;
##      print "Frequently Asked Questions on" >>$file;
##      print "$title</h1>\n" >>$file;
##      print "</center>" >>$file;

Quote:
}

#########################################################
#       Main body of program
#

while (<>) {
        chop;

        ($catagory, $question, $answer)
                = split(/&/, $_);

        if ($catagory eq "general") {
                $file = "faq-1.html";
                $type = "General Publishing Questions"; }
        elsif ($catagory eq "installation") {
                $file = "faq-2.html";
                $type = "Installation and Configuration"; }
        elsif ($catagory eq "distribution") {
                $file = "faq-3.html";
                $type = "Distribution"; }
        elsif ($catagory eq "forms") {
                $file = "faq-4.html";
                $type = "Electronic Forms"; }
        elsif ($catagory eq "viewing") {
                $file = "faq-5.html";
                $type = "Viewing Documents"; }
        elsif ($catagory eq "specific") {
                $file = "faq-6.html";
                $type = "Questions about Specific Publications"; }
        elsif ($catagory eq "printing") {
                $file = "faq-7.html";
                $type = "Printing Documents"; }
        elsif ($catagory eq "supplemental") {
                $file = "faq-8.html";
                $type = "Supplemental CD-ROM Production"; }

        if ($did_head eq "no") { &do_head;  }
        if ($catagory ne $cat_check) { &initial_cat; }
        else {$counter=$counter+1;}

        print "\t<li><a href=\"$file\#$counter\">$question</a>\n";

##      print "\t<li><a name=\"$counter\">$question</a>\n" >>$file;
##      print "\t\t<ul>\n" >>$file;
##      print "\t\t$answer\n" >>$file;
##      print "\t\t</ul>" >>$file;

        $cat_check=$catagory;

        $do_end = "yes";

Quote:
}

if ($do_end eq "yes") {print "</ol></body>\n</html>\n";

##      print "</body>\n</html>\n" >>$file;         <-----this really
goes at the end of each sub page.  If its here it will only end the
last page it creates

Quote:
}

exit;


Mon, 14 Dec 1998 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Perl on Win32: Output file redirection clobbers file?

2. output shows up in piped output file, but not on homepage

3. combining Curses.pm with output redirection

4. Question: Output redirection

5. Detecting output redirection in Perl

6. output redirection

7. Output Redirection

8. Crontab output Redirection

9. output redirection on NT

10. NT + Perl + redirection of output

11. redirection of script output

12. system() output screwing up redirection.

 

 
Powered by phpBB® Forum Software