0

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....

#!/usr/bin/perl

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)
		next
}
	print "checking required fields<br>";
	foreach (@required) {
    print "a required field $_.<br>";
	}

many thanks in advance
Sarah

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by KevinADC
0
foreach my $name (@required)
		$name = trim($name);
		next;
}

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.