Guten Morgen und vielen Dank,
für die Tipps. "use strict;" hat zumindest einmal soweit geholfen, dass ich die Fehler mit der Variablendefinition kapiert und mit "my" behoben habe.
Was ich nicht ganz verstehe ist, dass das ursprüngliche Script (s. oben) auf einer anderen Maschine richtig läuft. Auf der neuen Maschine ist Linux mit Perl v5.8.6 drauf.
Zurück zu meinem Problem, dass ich den Fehler finde. Dazu noch einmal das modifizierte Script:
Code:
#!/usr/bin/perl -w
# *** SETTINGS ***
use strict;
use warnings;
use CGI qw(param);
use GD;
my $width = "14"; # Width of the image
my $height = "18"; # Height of the image
my $digits_dir = "../images/digits"; # Relative path to the CGI-program
my $ending = "gif"; # png, gif, jpg, change it also in the HTTP header
my $lock = "1"; # Lock the counterfile at the moment of access, "1"=looked, "0"=unlooked
my $counter = "0";
my $currentvisitor = "0";
my $hosts = "0";
my $length = "0";
my $image = "0";
my $image_width = "0";
my $leftborder = "0";
my $rightborder = "0";
my $counterimage = "0";
my $point = "0";
my $position = "0";
my @image = "0";
my @digit = "0";
# *** PROGRAM ***
my $query = param("visible");
$hosts = $ENV{'REMOTE_ADDR'};
open (VISITOR, "<", "visitor.dat"),
$currentvisitor = <VISITOR>;
close (VISITOR);
open (COUNT, "<", "count.dat") || die "Can't Open Count Data File: $!\n";
if ($lock eq "1") {
flock COUNT, 2;
}
$counter =<COUNT>;
close (COUNT);
if ($hosts ne $currentvisitor) {
$counter++;
open (WRITE, ">","count.dat") || die "Can't Write Count Data File: $!\n";
print WRITE "$counter";
close (WRITE);
open (CURRENT, ">","visitor.dat");
print CURRENT "$hosts";
close (CURRENT);
}
#open (DATEI,"<",$hosts) or die $!;
$length = length($counter);
@digit = split(//, $counter);
# Create a new Image
if ($query eq "yes") {
$image_width = $length * $width + 32 + $width;
# Width = length * width of single image + 2*border + point
$counterimage = new GD::Image($image_width,$height);
my $a = 0;
while ($a < $length) {
open (GIF, "$digits_dir/$digit[$a]\.$ending");
$image[$a] = newFromGif GD::Image(GIF);
close (GIF);
$a++;
}
open (LEFT, "$digits_dir/left.gif");
$leftborder = newFromGif GD::Image(LEFT);
close (LEFT);
open (RIGHT, "$digits_dir/right.gif");
$rightborder = newFromGif GD::Image(RIGHT);
close (RIGHT);
open (POINT, "$digits_dir/point.gif");
$point = newFromGif GD::Image(POINT);
close (POINT);
$counterimage->copy($leftborder,0,0,0,0,$width,$height);
my $b = 0;
$position = 5;
while ($b < $length) {
$counterimage->copy($image[$b],$position,0,0,0,$width,$height);
$position = $position + $width;
$b++;
}
$counterimage->copy($point,$position,0,0,0,$width,$height);
$position = $position + $width;
$counterimage->copy($rightborder,$position,0,0,0,$width,$height);
# print HTTP header for GIF
print "Content-type: image/gif\n\n";
# print the image
print $counterimage->gif;
}
# end of program
exit;
Vor der Definition aller Variablen mit "my" bekam ich eine ganze Reihe Fehlermeldungen der Art:
Global symbol "$length" requires explicit package name at ./counter.cgi line 57.
Das ist jetzt weg, nachdem ich jede Variable definitiert und zumindest mit "0" bestückt habe.
Wenn ich jetzt
./counter.cgi
ausführe, dann tauchen diese Meldungen auf:
Bareword "GIF" not allowed while "strict subs" in use at ./counter.cgi line 84.
Bareword "LEFT" not allowed while "strict subs" in use at ./counter.cgi line 89.
Bareword "RIGHT" not allowed while "strict subs" in use at ./counter.cgi line 93.
Bareword "POINT" not allowed while "strict subs" in use at ./counter.cgi line 96.
Execution of ./counter.cgi aborted due to compilation errors.
Und wenn ich in dem Script alle Zeilen zwischen "Create a new Image" und "end of program" kommentiere, dann kommt wieder die Fehlermeldung:
Use of uninitialized value in string ne at ./counter.cgi line 54.
Use of uninitialized value in string ne at ./counter.cgi line 54.
Denn Grund für diese Meldung finde in line 54
Code:
if ($hosts ne $currentvisitor) {
nicht.
Und Deine Fehleabfrage
Code:
open(DATEI,"<",$dateiname) or die $!
habe ich nicht ganz verstanden. Kann ich damit abchecken, ob z.B.
$currentvisitor einen Wert erhalten hat, wenn ich
Code:
open(DATEI,"<",$currentvisitor) or die $!
schreibe? Bisher hatte ich open so verstanden, dass ich auf diese Art auf der Platte liegende Dateien öffnen und auslesen lassen kann.
Die beiden Dateien count.dat und visitor.dat haben die Rechte -rw-rw-rw-, werden aber nicht befüllt.
Grüsse
Eagle
Lesezeichen