[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

flock() on closed filehandle ?

Posted on 2002-07-27
7
Medium Priority
?
1,538 Views
Last Modified: 2013-12-25
Hello,
I'm having trouble with a perl script. I do not understand what the error means. This is what it says in my error log:
flock() on closed filehandle GetNews::TITLEFILE at /home2/blah/public_html/cgi-bin/GetNews/GetNews.pm line 105.

here's the trouble section in the script:
sub print_title
{
  shift;
  my $site_name=shift;
  my $file_desc=shift;
  my $site_url=shift;
 
  my $title_file=$html_template_path."/title.template";
  my $title="";
  open (TITLEFILE,"<$title_file") ||die "Cannot find title template file";
  flock(TITLEFILE,2);
  while(<TITLEFILE>)
  {
    $title=$title.$_;
  }
  flock(TITLEFILE,8);
  close(TITLEFILE);
  $title =~ s/SITEURL/$site_url/g;
  $title =~ s/SITENAME/$site_name/g;
  $title =~ s/FILEDESC/$file_desc/g;
  print $title;
  flock(TITLEFILE,8); << line 105
  close(TITLEFILE);
}

Any explainations/suggestions appreciated.
0
Comment
Question by:sayhi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Author Comment

by:sayhi
ID: 7181700
side thing (i don't know if it has to do with the error), Readme file said something like "you may need to 'chmod o+rx' the two .pm files and the directory".
can anyone explain what o+rx translates to? (all i know what to with chmod is with numbers like 777, 775, 644, etc)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7181814
your script closes the file on line 100
0
 
LVL 5

Expert Comment

by:Peewee
ID: 7184841
sayhi,
here's an explanation of whats going in your script:

the code below basically opens a filehandle 'TITLEFILE', provides it with exclusive access, stores the contents of the file into a variable, unlocks the file and closes the file handle 'TITLEFILE'.

============
open (TITLEFILE,"<$title_file") ||die "Cannot find title template file";
 flock(TITLEFILE,2);
 while(<TITLEFILE>)
 {
   $title=$title.$_;
 }
 flock(TITLEFILE,8);
 close(TITLEFILE);
==================

the code below basically performs regular expressions on the contents of the file now stores in the variabale and prints the variable out, this is more than likely a template with html content and attempts to unlock and close the filehandle 'TITLEFILE'.  This will not be successful as 'TITLEFILE' no longer exists at this point, and therefore is unable to complete and file locking process.

===========================
$title =~ s/SITEURL/$site_url/g;
 $title =~ s/SITENAME/$site_name/g;
 $title =~ s/FILEDESC/$file_desc/g;
 print $title;
 flock(TITLEFILE,8); << line 105
 close(TITLEFILE);


solution:
the code below is redundant in your script, either take it out or check that you have not missed some other code that should be present and accompanies this code.

let me know how it goes

regards Peewee
flock(TITLEFILE,8); << line 105
 close(TITLEFILE);
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:sayhi
ID: 7186399
"...attempts to unlock and close the filehandle 'TITLEFILE'.  This will not be successful as 'TITLEFILE' no longer exists at this point, and therefore is unable to complete and file locking process."

okay, I understand that. thanks for explaining.

Though could you explain what is this error telling me?:
flock() on closed filehandle GetNews::TITLEFILE at /home2/blah/public_html/cgi-bin/GetNews/GetNews.pm line 105

Is it saying that where flock() is on line 105, there is nothing to close? or I have to do what you did, go look at the code and see what the problem is. Just wondering, since I want to understand what it means if I ever come across this error again.

"solution:
the code below is redundant in your script, either take it out or check that you have not missed some other code that should be present and accompanies this code.

let me know how it goes

regards Peewee
flock(TITLEFILE,8); << line 105
close(TITLEFILE);"

I took it out. It worked! =)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 7186466
.. this all ends up in short words (see my very first comment :-)
0
 
LVL 5

Accepted Solution

by:
Peewee earned 200 total points
ID: 7187468
sayhi,

flock() on closed filehandle GetNews::TITLEFILE at /home2/blah/public_html/cgi-bin/GetNews/GetNews.pm line 105

what does this tell you?


'TITLEFILE' no longer exists at this point, and therefore is unable to complete and file locking process - hence the error.


your problem:
short solution take the offending code:
flock(TITLEFILE,8); << line 105
close(TITLEFILE);"

extra:
take a look at your code, and ask your yourself why you have a filehandle open when it has already benn closed, ie is this extra processing that has been deleted by mistake or is it because code was duplicated elsewhere by accident.

let me know if you need more help.

regards
Peewee
0
 
LVL 5

Expert Comment

by:Peewee
ID: 7190048
sayhi,

glad to be of help..

Peewee
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question