Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Need some direction

by barelahh (Initiate)
on Oct 15, 2014 at 17:35 UTC ( #1103942=perlquestion: print w/replies, xml ) Need Help??

barelahh has asked for the wisdom of the Perl Monks concerning the following question:

I am attempthing to write a script up that will reduce work load on website updates. This is what i wish to accomplish. Webpage which contains inventory with photos and description. Main page has thumbnail to click on to bring up a slideshow of photos withinformation below slideshow that is static. What i want to do is to store photos and a flat text file with the information to be brought in, as well as photos to be loaded and have the script place them in proper sequence and load them into slideshow. All photos and text files will be in a particular directory for that item. The script needs to be generic in that it is loaded upon a click on any photo. The photo being clicked on is the link to the directory where that information is stored. Can anyone direct me to a starting point or even a possible script already done that i can use to modify for what i want it to do? Thanks

Replies are listed 'Best First'.
Re: Need some direction
by blindluke (Hermit) on Oct 15, 2014 at 21:42 UTC

    Welcome to the Monastery. The task you are attempting is not a trivial one, but, if you are willing to give it a try, you will find that Perl is a great tool for the job.

    You need to look at the job in front of you in terms of input and output. Your input seems to be the name of a directory. Given the directory name, you want to write a script that will look into the directory, get the names of the image files, and the description from the text file, and produce an html file with the gallery - your desired output. Since you probably want to produced galleries with consistent look, you need to look at some templating tools to make your job easier. I would recommend HTML::Template.

    Start with creating a basic template file, gallery.tmpl.

    <html> <head> <style> div.img { margin: 5px; padding: 5px; border: 1px solid #0000ff; height: auto; width: auto; float: left; text-align: center; } div.img img { display: inline; margin: 5px; border: 1px solid #ffffff; } div.img a:hover img { border:1px solid #0000ff; } </style> </head> <body> <p> <TMPL_VAR NAME=DESCR> </p> <TMPL_LOOP NAME=GALLERY> <div class="img"> <a target="_blank" href="<TMPL_VAR NAME=IMG_BIG>"> <img src="<TMPL_VAR NAME=IMG_SMALL>" width="110" height="90"> </a> </div> </TMPL_LOOP> </body> </html>

    It contains one description field, and a loop that will create appropriate div blocks for every image.

    Try it out with the following code.

    #!/usr/bin/perl use v5.14; use HTML::Template; my $template = HTML::Template->new(filename => 'gallery.tmpl'); my @gallery; for my $count (1..3) { my %data = ( img_small => "img$count-small.jpg", img_big => "img$count-big.jpg", ); push @gallery, \%data; } $template->param(DESCR => "Some general description"); $template->param(GALLERY => \@gallery); print $template->output;

    If the names of the images in your directory happen to be 1-small.jpg, 1-big.jpg, and so on, and you are satisfied with the predefined string "Some general description" as your description, this could be what you want. But it probably isn't. Right now, we're producing the output, but we're ignoring the input completely.

    The next step would be to read the description from a file. Take a look at the File::Slurp module, and use it to read a plain text file in a given directory. Then, substitute the DESCR param with the description gathered from your file (the file contents). Then, take a look at Find all JPEG files in a directory, and expand the script a bit more. Then, your job will hopefully be finished.

    Good luck.

    - Luke

      Ahh Awesome someone who actually wants to help another person! Kool :) It is a start for what I wish to do. I didn't expect the code but thank you very much. It has been around 10 years since I've worked with perl and was not sure how much it has changed. SO this is a good start.
Re: Need some direction
by CountZero (Bishop) on Oct 16, 2014 at 06:17 UTC
    Perl has many nice web-frameworks which would be ideal for your needs. Check out Dancer, Dancer2 or Catalyst.

    One thing that is common to most web-frameworks is that they use template-engines to atually dynamically produce the web-page. I like Template Toolkit very much, but there are lots of template engines around.


    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics
      Thank you very much for the information.
Re: Need some direction
by InfiniteSilence (Curate) on Oct 15, 2014 at 21:00 UTC

    Yeah, there are websites you can go to like oDesk or where you can hire people to do what you want in Perl. This site is to help you with a specific problem or perhaps to expand upon some type of idea. What you have here are requirements, that's it.

    Celebrate Intellectual Diversity

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1103942]
Approved by Old_Gray_Bear
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (2)
As of 2022-05-16 21:11 GMT
Find Nodes?
    Voting Booth?
    Do you prefer to work remotely?

    Results (63 votes). Check out past polls.