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:
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]}, (' ')x($cols-@{$rows[-1]});
Tr [map td($_), @rows];
}
And my config file:
$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
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]}, (' ')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