Forum Moderators: coopster & phranque

Message Too Old, No Replies

My script isn't working

I need help!

         

adni18

2:06 pm on Oct 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My script is not working. Why? :

#!/usr/bin/perl

use CGI::Carp qw(fatalsToBrowser);

open (VIS,"grandvisits.txt");
$ha=<VIS>;
close VIS;
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time);
$combonation="$mday-$mon-$year";
@sp=split(/\¦/,$ha);
if(@sp[0]!="$combonation")
{
open (VIOB,">grandvisits.txt");
print VIOB "1";
close VIOB;
}
else{
$he=@sp[0]+1;
open (VIOS,">grandvisits.txt");
print VIOS "$combonation\¦$he";
close VIOS;
}

kaled

9:05 am on Oct 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well I'm no expert in perl, but I see a few faults.

@array[0] should be written as $array[0], etc.

I don't know why there is a comma in your split statement.

If you place use strict; at the top, your compiler may provide other clues. It will also require all vars to be declared either locally or globally.

Incidentally, stating that something doesn't work is not helpful. If you want help with a problem, you should state the exact nature of the fault.

Kaled.

adni18

12:27 pm on Oct 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, okay, first off, the script is supposed to detect if the current date is the one matched on my counter file, and if it doesn't, then it will start over the counter and write the previous results to another file. And why use the $ instead of @? The split is an array, right? Thanks for your help.

kaled

5:30 pm on Oct 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And why use the $ instead of @? The split is an array, right? Thanks for your help.

If element '$n' of array '@a' is a scalar, it should be accessed as $a[$n] NOT @a[$n].

Granted, this is weird, but this is Perl.

Kaled.

wruppert

3:30 am on Oct 6, 2004 (gmt 0)

10+ Year Member



if(@sp[0]!="$combonation") probably should be
if ($sp[0] ne $combonation).

!= is used to compare numerics, ne is used on strings. Because of the dashes, $combonation appears to be a string. Amazingly, the double quotes will actually work (due to variable interpolation), but are not needed.

cyberws

3:17 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



You should also run perl with the -w switch. This will help by getting Perl to help you with problems:

#!/usr/bin/perl -w