sayhi
asked on
flock() on closed filehandle ?
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/cg i-bin/GetN ews/GetNew s.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."/ti tle.templa te";
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.
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/cg
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
my $title="";
open (TITLEFILE,"<$title_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.
your script closes the file on line 100
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);
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")
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);
ASKER
"...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/cg i-bin/GetN ews/GetNew s.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! =)
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/cg
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! =)
.. this all ends up in short words (see my very first comment :-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sayhi,
glad to be of help..
Peewee
glad to be of help..
Peewee
ASKER
can anyone explain what o+rx translates to? (all i know what to with chmod is with numbers like 777, 775, 644, etc)