Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

comment on

( #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":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (7)
    As of 2020-11-25 23:25 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found

      Notices?