ActiveState Powered by ActiveState

ActiveState Community


Issue with brackets

Posted by bryanhalf on 2008-03-08 13:58
#! perl
init_words();
print "What is your name? ";
$name = ;
chomp ($name);
if ($name =~ /^randal\b/i) {
	print "Hello, Randal, how nice of you to be here!";
} else {
	print "Hello, $name\n What is the secret word? ";
	$guess = ;
	chomp ($guess);
	While (! good_word($name,$guess)){
		print "Wrong, Try again.  What is the secret word? ";
		$guess = ;
		chomp ($guess);
	}
}
## Subs from here down.
sub init_words {
	open (WORDSLIST, "wordslist") || die "Can't open wordslist file: $1";     # syntax open( FILE HANDEL, file name)
	while ( defined ($name = )) {  # basically checks every line until it gets a undef string, which is returned as false.
		chomp ($name);
		$word = ;
		chomp ($word);
		$words{$name} = $word;
	}
	close (WORDSLIST) || die "Couldn't close wordlist: $!"; 
}
sub good_word {
	my($somename,$someguess) = @_;
	$somename =~ tr/A-Z/a-z/;
	$someword =~ s/\W.*/""/
	if ($somename eq "randal") {
		return 1;
	} elsif (($words{$somename} || "groucho") eq $someguess) {
		return 1;
	} else {
	return 0;
	}
}

I made this and it wont compile because of syntax errors at the curly brackets...I have no clue whats going on, could someone help me out?

maldrac | Sat, 2008-03-08 16:27

On line 12 While (! good_word($name,$guess)){ While should be while

On line 32 $someword =~ s/\W.*/""/ possible missing ;

Other than that there are missing assignments... maybe just forum formatting?

-->