Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/usr/bin/perl ########################################################### # shtml publisher - v1.0 (25/01/01) # # Stephen Doolan (willdooUK @ hotmail.com) # # This is a utility that expands include statements # in shtml files, allowing you to view them without # running a web server. # # These include statments take the form: # <!--#include file="example.html"--> # # To use it, run the script and give it the names of # two directories - one containing the shtml files, and # the other which will contain the resulting html files # (these will have had any references to '.shtml' changed # to '.html') # # Note that at present this script only runs over a # flat directory structure. ########################################################### use strict; my $sIncBefore = "<!--#include file=\""; my $sIncAfter = "\"-->"; my $sShtmlDir = ""; my $sHtmlDir = ""; my $iArgCount = @ARGV; my $iChanges = 0; my $iFiles = 0; my $iChangedFiles = 0; my @files; ################### # Parse arguments ################### if($iArgCount < 2) { die("Usage: publish SHTMLDIR HTMLDIR"); } $sShtmlDir = @ARGV[0]; $sHtmlDir = @ARGV[1]; ##################### # Get list of files ##################### if(!opendir(directory, $sShtmlDir)) { die ("Could not open $sShtmlDir"); } @files = grep(/\.shtml/i, readdir(directory)); closedir(directory); $iFiles = @files; print "\nFound $iFiles files. Press any key to start.\n"; <STDIN>; ########################## # Loop through file list ########################## foreach(@files) { ################################ # Get filenames and open files ################################ my $sMadeChange = ""; my $sReadFilename = $sShtmlDir."\\".$_; my $sWriteFilename = $sHtmlDir."\\".$_; $sWriteFilename =~ s/shtml$/html/; print "\n$sReadFilename: "; if(!open(READFILE, $sReadFilename)) { die ("Could not open read file: $sReadFilename: !"); } if(!open(WRITEFILE, ">".$sWriteFilename)) { die ("Could not open write file sWriteFilename: !"); } ###################################### # Go through each line in shtml file ###################################### while(<READFILE>) { my $sLine = $_; # convert any references to '.shtml' $sLine =~ s/\.shtml/.html/; if($sLine =~ m/^(.*)$sIncBefore(.*)$sIncAfter(.*)$/) { $iChanges++; $sMadeChange .= "<Expanded> "; my $sBefore = $1; my $sInclude = $2; my $sAfter = $3; print WRITEFILE $sBefore; ############################ # Expand include statement ############################ my $sIncFile = $sShtmlDir."\\".$sInclude; if(!open(INCLUDEFILE, $sIncFile)) { die "Could not include $sIncFile: $!"; } while(<INCLUDEFILE>) { # convert any references to '.shtml' s/\.shtml/.html/; # write line to html file print WRITEFILE $_; } close(INCLUDEFILE); print WRITEFILE $sAfter."\n"; } else { print WRITEFILE $sLine; } } close(READFILE); close(WRITEFILE); #################### # Display progress #################### print $sMadeChange; if (!$sMadeChange eq "") { $iChangedFiles++; } } print "\n\nAll Done: $iChanges changes made on "; print "$iChangedFiles out of $iFiles files.\n"; exit;

In reply to shtml publisher by willdooUK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (1)
As of 2024-04-19 00:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found