spacer

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

home / experts / perl / tutorial / 3

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

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


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Search Engine Optimization: Selecting and Embedding Keywords · Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
IBM DB2 10 for z/OS: Justifying the Upgrade · Living La Vida Colo: Choosing the Right Colocation Facility · FTC Concerns over Social Media Privacy Linger


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

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