Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
#!c:/Perl/bin/perl ## HOST: intranet #!/usr/bin/perl ## HOST: 1dollarhosting #!/usr/local/bin/perl ## HOST: verio # define script defaults (change these to suit your needs) my %defaults = ( path => "", debug => "", ); # define script properties (don't change these) my %script = ( name => "frankenpage", version => "1.02", release => "Final", author => "Sean Shrum", email => "sean\@shrum.net", created => "2001.03.22", modified => "2002.03.23", status => "open source", distribute => "http://www.shrum.net/programm +ing", ); # define script error messages (don't change these) my %errors = ( header => "$script{'name'} v. $script{ +'version'} [ $script{'release'} ] by $script{'author'} ( $script{'ema +il'} ) - $script{'status'}\n\n", nopath => "No PATH parameter was specifi +ed.\n", badpath => "Unable to open the specified + PATH.\n", badsource => "Unable to open the specified F +ILE.\n", ); ###################################################################### +########## # # WHAT DOES THIS SCRIPT DO? # Reads a directory of files and builds a form that allows you to s +pecify what # to include/omit in the final result. Upon submitting, the script + pulls the # files you selected in the order your chose and builds the page. # # WHY ARE THE NOTES DOWN HERE? # Typically, you open up a script and this section is the first thi +ng you # see. Not with my scripts. Why? Well, it makes it easier to par +se the # script file for various important items, things like the version +#, # release, status, etc. As a result, I moved this section below th +em in # the event that I write something like "..this version contains... +", my # parsing scripts don't get the two confused. This is really for m +y own # reasons. Once you have d/l'ed the script, feel free to move this + section # where ever you like. # # WHERE ARE THE SCRIPT REQUIREMENTS, INPUT, OUTPUT, FAQs, ETC.? # To reduce the amount of redundant write up that I have to do, # all info pertaining to the use of this script has been centralize +d. # on my website. Go to www.shrum.net/programming and do a search # on the script name for the latest source and white paper discussi +on # Use these resources first if you need any information. # # SUPPORT AND LEGAL ISSUES: # See http://www.shrum.net/programming/legal for information. # ###################################################################### +########## # to access REMOTE files use LWP::Simple; # to handle parameter passing use CGI; # to display more meaningful error messages to the browser use CGI::Carp qw(fatalsToBrowser); # check if the DOCUMENT_ROOT environment variable is defined my $rootPath = "$ENV{'DOCUMENT_ROOT'}/" || ""; # get the parameters; 1st from the ARGV array or the QUERY_STRING if (@ARGV) { $input = new CGI ( join "&" => @ARGV ); } else { $input = + new CGI; } # check for input; if no parameters are supplied, redirect to technica +l white paper unless ( $input->param() ) { print $input->redirect( $script{'distribu +te'} . '/redirects/' . $script{'name'} . '.shtml' ); exit; } # set defaults for parameters omitted by user for ( keys %defaults ) { $input->param(-name=>$_,-value=>$defaults{$_} +) unless $input->param($_); } # check for required parameters if ( ! defined $input->param('path') ) { die $errors{'header'} . $erro +rs{'nopath'}; } # see if this is part of a SSI call, if not print out the HTML header print $input->header unless @ARGV; ###################################################################### +########## # for debugging if ( $input->param('debug') ) { print "<p>Retrieving file list..."; } # open the user specified directory opendir (DIR, $rootPath . $input->param('path')) or die $errors{'heade +r'} . $errors{'badpath'}; # fill the array with all the filenames in the specified PATH #@files = grep { !/^\./ && -f } map {$rootPath . $input->param('path') + . "/" . $_ } readdir DIR; @files = readdir DIR; # close the directory closedir(DIR); # sort the array @files = sort @files; # get the number of files $num_files = $#files + 1; # for debugging if ( $input->param('debug') ) { print $num_files . " found."; } # initalize $page my $page = ""; # see if we are building the final resume if ( $input->param('s1') ne "" ) { # for debugging if ( $input->param('debug') ) { print "<hr><p>Building PAGE...</p> +"; } # for debugging if ( $input->param('debug') ) { print "<hr><p>...adding section "; + } # loop through each possible iteration foreach ( @files ) { # increment the count $count++; # for debugging if ( $input->param('debug') ) { print $count . ","; } # see if the user selected a entry $skey = "s" . $count; if ( $input->param($skey) ne "" ) { # retrieve the defined file $section = &get_data( $rootPath . $input->param('path') . +"/" . $input->param($skey) ); # see if the user requested a HR be inserted above this se +ction $ckey = "c" . $count; if ( $input->param($ckey) ) { $break = "<hr>"; } else { $b +reak = ""; } # add the result to the page $page = $page . $break . $section; } } } else { # for debugging if ( $input->param('debug') ) { print "<hr><p>Building FORM...</p> +"; } # build the section_template $page = "<H1>Welcome to Frankenpage</h1><p><font size=2>The <i>on- +the-fly-slap-it-together</i> web page construction Script.</font><P>L +ooks like you'll be building a page from the contents of " . $input-> +param('path') . "."; # make the script call itself again $page = $page . "<p><form method=\"GET\" action=\"" . $ENV{'SCRIPT +_NAME'} . "\">"; # for debugging if ( $input->param('debug') ) { print "<hr><p>...adding section "; + } # create a combobox for each file (in case the user wants everythi +ng). foreach ( @files ) { # increment the count $count++; # for debugging if ( $input->param('debug') ) { print $count . ","; } # start off the section $section = "<P>" . $count . ". <select size=\"1\" name=\"s" . +$count . "\"><option selected> </option>"; # create a entry for each file in each combobox. foreach ( @files ) { $section = $section . "<option>" . $_ . " +</option>"; } # cap off the SELECT tag and add a checkbox $section = $section . "</select> <input type=\"checkbox\" nam +e=\"c" . $count . "\" value=\"y\"> Break before this section with hor +tizontal rule"; # add the section to the page $page = $page . $section; } # for debugging if ( $input->param('debug') ) { print "</p>"; } # add a submit button and cap off the FORM tag $page = $page . "<p><input type=\"hidden\" name=\"path\" value=\"" + . $input->param('path'). "\"><input type=\"Submit\" value=\"Built it +!\" name=\"B1\"><input type=\"reset\" value=\"Start Over\" name=\"B2\ +"></form>"; } # for debugging if ( $input->param('debug') ) { print "<hr><p>Printing...</p>"; } # display page print $page; # quit exit; ######################################## sub get_data ( $source ) { # pass the arguments to localized variables my $source = $_[0]; # make sure that the source is defined if ( $source ) { # for debugging if ( $input->param('debug') ) { print "<hr><p>...openning loca +lly hosted file: $source<P>"; } # open the local file open ( DATA, $source ) or die $errors{'header'} . $errors{' +badsource'} . "\n\nSource: $source"; local($/) = undef; # place the raw contents of the file into a variable $data = <DATA>; # close the file close (DATA); } # return the results return $data; }

In reply to Frankenpage: Build on-the-fly customizable web pages from a directory of files by S_Shrum

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!
  • 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
  • Outside of code tags, you may need to use entities for some characters:
            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 about the Monastery: (4)
    As of 2014-09-22 02:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (177 votes), past polls