467,179 Members | 1,217 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,179 developers. It's quick & easy.

Perl writing to a file some problem

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
  • viewed: 1504
Share:
3 Replies
KevinADC
Expert 2GB
Is this a Windows environment? Flock is not supported on Windows.
Sep 7 '08 #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 2GB
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.

Similar topics

14 posts views Thread by Xah Lee | last post: by
52 posts views Thread by Olivier Scalbert | last post: by
9 posts views Thread by Martin Foster | last post: by
1 post views Thread by smsabu2002@yahoo.com | last post: by
reply views Thread by Kirt Loki Dankmyer | last post: by
6 posts views Thread by Keith Lee | last post: by
10 posts views Thread by masinick | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.