in reply to Re: german nouns gender
in thread german nouns gender
One of the main things enforced by strict is that you need to declare your variables, typically with my.
Here is the code you provided, in the <code> tags:
A few problems:#use strict; #use warnings; open (FILE, 'german.txt'); @words = <FILE>; $num = int rand(@words); ($article, $noun) = split(/ /, $words[$num]); chomp($noun); print "Who is the article of $noun:"; chomp($resp = <>); if ($resp eq $article) { print "Correct!"; } else { print "The correct answer is $article!" }
use strict; use warnings; open (FILE, 'german.txt') or die "Failed to open german.txt - $!"; my @words = <FILE>; my $num = int rand(@words); my ($article, $noun) = split(/ /, $words[$num]); chomp($noun); chomp($article); print "Who is the article of $noun:"; my $resp = <>; chomp $resp; if ($resp eq $article) { print "Correct!"; } else { print "The correct answer is $article!" }
|
|---|