spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / perl / tutorial / 3

Developer News
Google Chrome Playing Catch-Up on Extensions
Open Solutions Alliance Gets New Leadership
Red Hat Spacewalk Expands Linux Management

PerlHoo, Part II

Storing User Recommendations

Now we must deal with a few issues related to storing new site recommendations. When a user wants to recommend a new site for a particular category, he/she clicks the link labeled Suggest new link at the bottom of the directory page. This link is created dynamically in the print_footer subroutine (Lines 152-157). This calls the print_add_screen subroutine (Lines 99-122) which prints the form. The form is similar to the one below:

URL:
Title:
Description:
Your Name:
Your Email:

When the user completes the form and clicks the Submit Resource button, the data is sent back to the script. Assuming the form method is POST, the add_link subroutine (Lines 55-91) appends the information to $rootdir/$reldir/$new_datafile which in our case would be /www/directory/Computers/Perl/perlhoo_new.csv if the category was Computers/Perl.

File Permissions

Because we're writing to files now, we must make sure that our Web server has proper permissions. Make sure the PerlHoo directory defined in the $rootdir variable on Line 32 is writable by your Web server.

File Locking

The add_link subroutine stores new site recommendations in a CSV file when the user clicks the Submit Resource button. This can cause a race condition where multiple users submit a new site simultaneously. In such a case, only the second set of data would be added to the file.

To solve this potential problem, add_link requests an exclusive lock on the file before it writes to it. This will ensure that data will not be lost. In Line 60, we open the data file in append mode. Then we request an exclusive lock in Line 61. We combine the form data into a CSV record in Lines 63-65 and write it to the file. The lock is released when the file handle is closed in Line 66.


home / experts / perl / tutorial / 3

http://www.internet.com

Produced by Jonathan Eisenzopf and

internet.comearthweb.comDevx.commediabistro.comGraphics.com

Search:

Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

Jupitermedia Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

webref The latest from WebReference.com Browse >
Popular JavaScript Framework Libraries: An Overview - Part 3 · Accessing Your MySQL Database from the Web with PHP · Working with the DOM Stylesheets Collection
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags


Created: April 20, 1999
Revised: April 21, 1999

URL: http://www.webreference.com/perl/tutorial/3/