problem with file structure and presentation

Posted on 2003-03-17
Medium Priority
Last Modified: 2010-03-05
Hello members,

I just signed up, I've found this site to be useful not only to ask questions but to also help others.

This time around I do have a question.

I have a website that will incorprate email postcards. Everything works fine but I want to add a ranking system on the most popular postcards sent.

I already feel that I'm not making any sense.

Here is my file structure.

POSTCARDS : here i have the main postcard page and all category pages that displays the picture and the page that collects the user information to send the postcard. I also have a folder called "images" that holds the pictures

IMAGES : here i have subdirectories of every category (5). within those subdirectories are thumbnail and full size pictures marked ####.jpg and ####_tn.jpg respectfully.

CARDSTAT file : this file is where I store the ranks of every picture. one line from this file looks like the following:  ####.jpg,100

THE PROBLEM : For every card sent a cgi script runs to rewite the postcard's main page updating the 3 most popular pictures. I do have the picture's file name of those popular pictures but I can't find a way to locate which directory they are in.

IDEAS: code the cgi script to search for file name within all directories and retain the path in a variable when that file is found. or restructure the location of those directories. or instead of having just the picture's file name in the CARDSTAT file write out the path as well.


Question by:lunatic359
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
LVL 20

Expert Comment

ID: 8156778
At the risk of suggesting "premature optimization", I think you want to avoid having your CGI script do an extensive search on every transaction. As your site gets busier, that could be a killer. I'd also start to be concerned about mutual exclusion issues on the updates.

That being said, the simplest solution for a low-volume site would be to fix the format of your CARDSTAT file so it included the pathname of each file instead of just the file name. A second alternative would be to create a separate FILELOC file that tied filenames to their proper directories.


Expert Comment

ID: 8158167
how about something like this?

set up a cron job to run once an hour or two hours or whatever.

have if start at your root image directory and find all the files. Then use that path and basename to do your mapping.

$toRoot = '/path/to/root/image/dir';

@files = `find $toRoot`;
open(OF, ">/path/to/imageMap/file.txt");

foreach $f (@files) {

  $file = `basename $f`;
  $path = "$toRoot/$f";

  print OF "$file=$path\n";


Then, in your cgi, you can search the file for your lookup.

Author Comment

ID: 8161487
OK, I did find a way to locate the 3 most popular pictures' location. But now I'm considering what jmcq had stated about optimization. It is also a pain to type out all 150 pictures' path. So I guess I could write a cgi script that searches for these pictures once, write the paths in the CARDSTAT and then use the CARDSTAT to locate them. Does this sound more effiecent?

Thanks guys..

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

LVL 26

Expert Comment

ID: 8161696
I have a couple of recommendations:

1) Include the path in the CARDSTAT file.  That looks to me to be the best solution.
2) Change CARDSTAT from a text file into some other format.  What you're doing would seem to fit one of the dbm file modules well (DB_File, GDBM_File, NDBM_File, SDBM_File, ODBM_File).  You should see a significant speedup in searching the file and [re]writing the file.

Author Comment

ID: 8163308
thanks wilcoxon I'll look into that dbm modules.. Never used one before... will i be able to edit one line within the db file?

LVL 26

Accepted Solution

wilcoxon earned 300 total points
ID: 8163412
Basically, the way the dbm modules work is you tie a hash to the file and the file stores (in a fast binary format) the hash.  So, once you do the tie line, you treat it just like a normal (simple) hash (eg $tied_hash{###.jpg} = 100 will save the value 100 to the file for ###.jpg).  If you need more than a scalar value in your hash, then you need to use MLDBM.  Let me know if you have more questions on all the dbm modules.

Author Comment

ID: 8178631

thanks for the info, I'm not to keen on using hashes or dbm modules. I do have two questions for you though or anyone who would like to answer it.

Is there any good websites or books pertaining to this?

and would it be better to use PHP instead? (omiting learning curve).

LVL 20

Expert Comment

ID: 8180293
The first part of Ch 14 in _The Perl Cookbook_ covers the use of the various DBM modules.

On this particular aspect, PHP has no advantage over Perl. You might still prefer PHP overall for the project.

Author Comment

ID: 8184714
thanks again, I'll look into it...

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question