By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,903 Members | 1,104 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,903 IT Pros & Developers. It's quick & easy.

Perl writing to a file some problem

P: 2
Hello scripters

Requirement:
I am trying to write a perl script that manipulate a html file. Both the html file and the script are placed at central server. I have scheduled one more script in client PC to run at start-up, that calls this server script with required arguments and the HTML page is updated accordingly. This is not server client architecture but a static server script called from client PC
The problem:
The scripts I have written (Server and PC) are working fine up to the point that the HTML page is updated correctly, but some times the HTML page becomes BLANK .
I am not able to pinpoint the problem. Below is the Server script

# The runtime argumnents must be of form : #
# labcar_name Working/locked user_id Date&time #
# or #
# Labcar_name free date&time #
# #


Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. use Fcntl qw(:flock);
  3. use strict;
  4. my $html_file ="\\\\aaa_edc_nts1\\edc_info\\Quality\\EDT\\38_EDT3\\39_Lab Eye\\webpages\\labeye_Intranet.html";
  5. my $log_file = "\\\\aaa_edc_nts1\\edc_info\\Quality\\EDT\\38_EDT3\\39_Lab Eye\\webpages\\user.log";
  6.  
  7. my $SEMAPHORE = $html_file . '.lck';
  8. open(S, ">$SEMAPHORE") or die "$SEMAPHORE: $!";
  9. flock(S, LOCK_EX) or die "flock() failed for $SEMAPHORE: $!";
  10.  
  11. open(LOG1,">>$log_file") or die "$log_file: $!";
  12.  
  13. my $filesize = -s "$html_file";
  14.  
  15.  
  16. print LOG1 "\n@ARGV $filesize\n";
  17.  
  18. close LOG1;
  19.  
  20.  
  21. open (PARSED_FILE,$html_file) or die "Cannot open the file";
  22.  
  23. my @parsed_file;
  24.  
  25. # Some processing logic here depending on the arguments 
  26.  
  27.  
  28. close PARSED_FILE;
  29.  
  30. print "\n TRYING TO WRITE TO FILE";
  31. open (OUTPUT_FILE,"+>$html_file") or die "Cannot open the file";
  32.  
  33. seek(OUTPUT_FILE,0,0);
  34.  
  35. print OUTPUT_FILE @parsed_file;
  36.  
  37. close OUTPUT_FILE;
  38. close S;
Sep 7 '08 #1
Share this Question
Share on Google+
3 Replies


KevinADC
Expert 2.5K+
P: 4,059
Is this a Windows environment? Flock is not supported on Windows.
Sep 7 '08 #2

P: 2
Is this a Windows environment? Flock is not supported on Windows.
yup i am working on windows .. is there any other method to prevent race around condition for file writing ...?
Sep 8 '08 #3

KevinADC
Expert 2.5K+
P: 4,059
Not that I know of.
Sep 8 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.