Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does "Useless use of string in void context" mean?

Status
Not open for further replies.

Tama

MIS
Jun 6, 2001
121
NZ
I run a tiny little Perl script on my site that I bodged up by myself. The script runs fine, but I get the following line in my servers error logs
Code:
Useless use of string in void context at linklog.cgi line 10.

The script looks like this:
Code:
#!/usr/bin/perl -w

#use strict;

#Thanks to Nuxy from [URL unfurl="true"]http://www.tek-tips.com[/URL] for the base of this script

my $logfile = "/home/vorb/[URL unfurl="true"]www/link/linklog.csv";[/URL]
my $time = gmtime;

open (FILE, ">>$logfile") || "can't open $logfile";
print FILE ("$ENV{'QUERY_STRING'},$ENV{'HTTP_REFERER'},$time\n");
close (FILE);
exit;

I know I'm missing something obvious, but I can't work out what - any ideas?

Cheers
Tama
 
So obvious that you can expect nobody can see it :

open (FILE, ">>$logfile") || or die("can't open $logfile");

instead of

open (FILE, ">>$logfile") || "can't open $logfile";


 
The line should read:

open (FILE, ">>$logfile") or die "can't open $logfile";

You weren't explicitly telling perl what to do with the string literal.

In situations where you have a line that will perform an action, or if that one fails a default action, use the "or" operator, not the "||" operator. "or" has a lower precedence than "||", which reduces the chances that you will ge weird behavior from your code in the event that the first action uses logical operators.

______________________________________________________________________
TANSTAAFL!
 
Sorry Tama, there's a mistake in my corrected line.
Thanks sleipnir214.
 
Hi guys, thank you for your quick responses.
I've changed the line to
open (FILE, ">>$logfile") or die "can't open $logfile";


And it's now spitting out this line
Code:
Premature end of script headers: /www/vorb/cgi-bin/linklog.cgi
in the error logs.
 
When 'die' is called it terminates the program and spits out the message you give it. If this is running from a CGI script the message gets sent to the server error log, and the default classic '500 Internal Server Error' gets sent to the browser.

The problem lies with your $logfile. For some reason (possible the file permissions don't allow it to be appended to) the script is failing. There are 2 things you could do to see the error.

First change the line to:

open (FILE, ">>$logfile") or die "can't open $logfile: $!\n";

The $! internal variable should give a more verbose description of the problem.

Or secondly, you could add the following to the top of your code after the shebang line (#!/usr/bin/perl):

use CGI::Carp qw(fatalsToBrowser);

This will then send nice error messages to your browser. However, make sure the line is removed for production code, as it can sometimes give away a bit too much information. Barbie
Leader of Birmingham Perl Mongers
 
Hi msbarbell

Sorted! Thank you for all your help guys... 15 hours in front of the PC today... yargh...

Cheers
Tama
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top