Hi there,

I can't get this foreach loop to work.

It says "Global symbol "$name" requires explicit package name at d:\domains\jacamar.co.uk\wwwroot\cgi-bin\Process_login.pl line 25."

which is presumably because I haven't declared it as "my $name" somewhere but what do I declare it as - if I do "my $name = ""; to make it blank it doesn't like that either saying it couldn't change a constant....


use strict;
use warnings;
use CGI;
use CGI::Carp qw/fatalsToBrowser/;
use Fcntl qw(:flock);

my $query = new CGI;

print "Content-type: text/html\n\n"; # must send a header first

my $requiredFields = $query->param('_requiredFields');
my @required = split(/,/, $requiredFields);

# Create a test string
my $string = "  \t  Hello world!   ";

# Here is how to output the trimmed text "Hello world!"
print trim($string)."<br>";

#If required fields are specified, check them.
if (defined $query->param('_requiredFields')) {
#  my @required = chomp($query->param("_requiredFields"), ",")
		foreach $name (@required)
			$name = trim($name)
	print "checking required fields<br>";
	foreach (@required) {
    print "a required field $_.<br>";

many thanks in advance

foreach my $name (@required)
		$name = trim($name);

the "next" keyword in the above loop is unecessary.