Did you know LQ has a Linux Hardware Compatibility List?
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 04-06-2010, 06:48 AM   #1
Registered: Dec 2009
Location: Hyderabad,India
Distribution: RHEl AS 4
Posts: 215

Rep: Reputation: 32
Unable to append to a file through perl/CGI

Hi folks,
Please look at the following code, where I'm trying to demonstrate the file locking concept through Perl/CGI.
Here is the script which I tried.
#!/usr/bin/perl -w
use strict;
use warnings;
print "Content-type: text/html\n\n";
print <<EOF;
<title>File Locking</title>
<body bgcolor = "#556677"></body>
<center><h1>Demonstrating File locking concept</h1></center>
my $myfile = "Employee.txt";
my $employee = "Manoj";
open(MYFILE, "$myfile");
flock(MYFILE, 1);
while(defined($a=<MYFILE>)) {
  if ($a=~m/^$employee$/) {
  print "<center>You are already in the list!\n</center>";
open(ASH, ">> $myfile");
flock(ASH, 2);
print ASH $employee;
print "<center>You are now in the list!\n</center>";
print "<body><html>";
Here, I'm not able to append the text and also unable to lock(shared lock) the file.
For your information, this is executing fine when I run the same as as
perl filelock.cgi
But when I run the same script in a browser, I'm not getting it fine.
Please assist me.
Old 04-06-2010, 01:48 PM   #2
Senior Member
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
Check your error logs. You don't need use warnings, you have -w
And use is not for warnings anyway.
Old 04-06-2010, 08:44 PM   #3
LQ 5k Club
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905Reputation: 905
The script has a whole world of different capabilities when run as a logged-in user compared to running as a CGI under a HTTP server userID. One principle of security is to disallow writes in the document root, server root, and cgi-bin directory.
How do you run a script in a browser?

--- rod.


cgi, file

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
while loop creates a problem for a file opened in append mode for writing in PERL gaynut Programming 2 07-28-2008 08:26 PM
[Perl] append to new file noir911 Programming 5 02-08-2007 07:38 AM
[Perl] append columns to file noir911 Programming 3 02-08-2007 06:29 AM
Perl cgi Script can`t make file.Why? ZairSadiqov Linux - Software 1 11-22-2006 08:22 AM
cgi perl : I cant get perl to append my html file... the_y_man Programming 3 03-22-2004 06:07 AM

All times are GMT -5. The time now is 02:09 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration