473,394 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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
3 1709
KevinADC
4,059 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
4,059 Expert 2GB
Not that I know of.
Sep 8 '08 #4

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

Similar topics

14
by: Xah Lee | last post by:
Just bumped into another irresponsibility in perl. the crime in question this time is the module File::Basename. Reproduction: 1. create a directory containing a file of this name:...
52
by: Olivier Scalbert | last post by:
Hello , What is the python way of doing this : perl -pi -e 's/string1/string2/' file ? Thanks Olivier
6
by: john brown | last post by:
I'm new to perl programming and would like some help if at all possible. I'm trying to make a simple script where I can input a filename. To be exact something like "/home/song1.mp3". I want to...
9
by: Martin Foster | last post by:
Hi. I would like to be able to mimic the unix tool 'uniq' within a Perl script. I have a file with entries that look like this 4 10 21 37 58 83 111 145 184 226...
1
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
0
by: shintu | last post by:
Hallo, I am trying to write french accented characters é è ê in Excel worksheet using my perl script , But I am stuck here as I couldnt find a way of writing it !: My code: use strict;...
1
by: pvenu | last post by:
Hi, I know basic perl (regular expressions, pattern matching, string manipulation, reading writing into text files). Yet, my requirement is to read an input text file -> process this input file...
6
by: Keith Lee | last post by:
All: I am attempting to compile the perl module Device::SerialPort and get this error during make -- Manifying blib/man3/Device::SerialPort.3pm Can't open blib/man3/Device::SerialPort.3pm for...
10
by: masinick | last post by:
I am aware that Perl has a lot of features that originally came from sed and awk. I have a pattern that I am using like this: sed -n '/|Y|/p' I want to do the same thing in Perl and be able to...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.