Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I'm trying to make a vary simple but flexible script to read the number a files in a directory and output the current, previous, and next items with the previous and next items check to make sure they stay within the total number of files. It would be used to make a web page where you can browse pictures but since most of the coding is done in the template I assume it could be used to view just about any sequentially numbered set of files. Any pointers on making it better/faster/more virsatile?
#!/usr/bin/perl -w ## Modules and setup use CGI; use HTML::Template; ## check perldoc HTML::Template for more informati +on use strict; $CGI::POST_MAX=1024 * 1; # max 1k post $CGI::DISABLE_UPLOADS = 1; # No uploads ## Setup vars my $ThisScript = 'pictureview.cgi'; my ($q) = new CGI; my $DisplayPicture; my $DirPath; ## Check for picture peram if ($q->param('Picture')) { $DisplayPicture = ($q->param('Picture'))*1; } else { $DisplayPicture = 1; } ## Count number of files. my @LFiles = (); opendir (DIR, "./"); @LFiles = grep {not /^(\.\.?|template\.html|pictureview\.cgi)$/} readdir(DIR); closedir (DIR); my $TotalFiles = $#LFiles + 1; ## Correct to first file = 1 my $PreviousPicture; my $NextPicture; ## ## Make sure numbers are good (Bounds checking) ## if ($DisplayPicture == 0) { $DisplayPicture = 1;} if ($DisplayPicture > $TotalFiles) { $DisplayPicture = 1;} if ($DisplayPicture == 1) { $PreviousPicture = $TotalFiles; } else { $PreviousPicture = $DisplayPicture - 1; } if ($DisplayPicture == $TotalFiles) { $NextPicture = 1;} else { $NextPicture = $DisplayPicture + 1; } ## Load template my $Template = HTML::Template->new(filename => "./template.html"); ## Insert vars into template $Template->param('PreviousPicture' => "$PreviousPicture"); $Template->param('PictureToView' => "$DisplayPicture"); $Template->param('NextPicture' => "$NextPicture"); ## Print Header and Template print $q->header, $Template->output(); ## Bye exit;
P.S. I'm positive this has been done before but what the heck I can make one as too.

------
PT - Perl Tanks %100 Perl programming game


In reply to How can it be done better? by SilverB1rd

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 romping around the Monastery: (2)
As of 2024-04-26 03:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found