Gossamer Forum
Home : General : Perl Programming :

Why won't this work???

Quote Reply
Why won't this work???
I am now working on a shopping cart for my site, and am using a config file for easy edit of variables, however, this is not working for some reason.. in shop.cgi (Early stages not near completion). I have:
Code:
#!/usr/bin/perl
print "Content-type: text/html\n\n";

require "shopconfig.cgi";

use CGI qw(:standard);
use strict;

&print;


sub print {

open(FILE, "shopdb.txt");
while(<FILE>) {

# Read the data into array of arrays
my @data = map { chomp; [split /\|/] } <FILE>;


# Print a multicolumn table of the first data column
my @td = map a({href=>"/$_->[3]"}, $_->[0]), @data;
print table( {border => 1}, multicol_table(2, @td) );
}

close(FILE);

print end_table;


}

# Multicolumn table subroutine
sub multicol_table {
my($cols, @data) = @_;
my(@rows, @row);
push @rows, [@row] while @row = splice @data, 0, $cols;
push @{$rows[-1]}, ('&nbsp;')x($cols-@{$rows[-1]});
Tr [map td($_), @rows];
}

And my config file:

Code:
#!/usr/bin/perl

$scripturl = "http://www.crashinto.com/cgi-bin/easyshop.cgi";

Now the problem is, when I place $scripturl inside my @td = map a({href=>"/$_->[3]"}, $_->[0]), like

my @td = map a({href=>"$scripturl/$_->[3]"}, $_->[0]),

it comes with an error of Global symbol "$scripturl" requires explicit package. Even if I do $scripturl = "........"; on the same cgi file it still does that. And if I try to do $scripturl anywhere in the script it still says that error.. That seems very strange for that not to print anywhere.
-------------
Jeremy
http://lc.crashinto.com - Crashinto Learning Central

Last edited by:

nolimit: Sep 14, 2001, 4:34 PM
Quote Reply
Re: [nolimit] Why won't this work??? In reply to
At the top of your main script add:

use vars($scripturl);

(Using strict requires this)

If $scripturl wasn't a global you'd fix that error by using

my $scripturl = " ... ";

.......instead of

$scripturl = " ... ";

Last edited by:

PaulWilson: Sep 14, 2001, 7:38 PM