[MacPerl] Uninitialised level of frustration...

[email protected] (Richard Smith) Mon, 29 Jan 2001 21:17:39 +0000
Newsgroups perl.macperl.webcgi
Message-ID <B69B8E73.1D30%[email protected]>
Hi All,

Since my Perl is improving, I now feel safe to start using the -w switch
when debugging my scripts without being buried under the weight of error
messages. However, I have encountered an uninitialised variable error that I
just cannot solve. I use a small library of common routines in all my CGI
scripts, which I include using the following method:
__________________
#!/usr/local/bin/perl -w

use strict;
use vars qw($filePath %Form %ENV);

my $settings = 'settings.txt';
my $sharedLib = 'sharedLib.pl';
require $settings;
require $sharedLib;

## Rest of script
________________

The problem lies in the 'sharedLib.pl' file. I have shuffled the variable
definitions around until I am blue in the face, but I get the same 'Use of
uninitialised variable in line xx' every time. The start of the problem
script, and the sub routine causing the problems is as follows:

#!/usr/local/bin/perl

#    This module contains a number of shared subroutines used by various
scripts on the Team Artonomy site

my @referers = ('hypermart.net','www.team-artonomy.com');    # Only sites in
this list can use this script
$errorMessage = 0;

return 1;

############################################################################
########
#######                            Shared subroutines
########
############################################################################

####### Routine to check that the script is called from the correct location

sub checkUrl {

    # Check that the script has been called from the right site.
    local ($level, @exactCheck);
    local $checkReferer = 0;
    $level = shift;
    @exactCheck = @_;    #    Grab any variables passed
    
    ($level eq 'strict') and push @referers, @exactCheck; #    If any extra
URLs have been passed, add them to the list
    # If a referring URL was supplied by the server, for each valid referer
make sure that a valid URL was passed to the script.
    if ($ENV{'HTTP_REFERER'}) {
        foreach (@referers) {
            $ENV{'HTTP_REFERER'} =~ m|https?://([^/]*)$_|i
            and $checkReferer = 1
            and last;
        }
    } else {
        #    Don't generate the error if the referer was not included
        #    (eg from a browser bookmark) unless the checking level is set
to 'strict'. 
         $checkReferer = ($level ne 'strict');
    }
    return $checkReferer;     # If the referrer is invalid, return a false
value. Otherwise return a true value.
}

The line causing the headache is:

   ($level eq 'strict') and push @referers, @exactCheck;

I would be extremely grateful if anyone could point out where I am going
wrong. Obviously, I can avoid the problem by turning off the -w switch
(which I remove in the online versions anyway), but it is the principle of
the thing.

Any advice much appreciated.

Richard
-- 

Richard Smith
Artist/ Illustrator/ Site Designer

Team Artonomy,
Drawing Business

http://www.team-artonomy.com
[email protected]
ICQ #29343811