Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: german nouns gender

by smokemachine (Hermit)
on Nov 08, 2006 at 16:37 UTC ( [id://582913] : note . print w/replies, xml ) Need Help??


in reply to german nouns gender

coud be this?
$|=1; @data = <DATA>; while($resp ne "q"){ $num=int rand(@data); ($a,$b)=split/ /,$data[$num]; print "$b: "; chomp($resp = <>); print $a eq lc $resp?"Rigth\n":"Wrong\n" } __DATA__ das Zimmer die Brille der Reisebus

Replies are listed 'Best First'.
Re^2: german nouns gender
by davorg (Chancellor) on Nov 08, 2006 at 16:41 UTC
    ($a,$b)=split/ /,$data[$num];

    It's generally a bad idea to use $a and $b a general variables in Perl programs. They are special variables that are used in sort routines and that's the only place where they should be used.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

Re^2: german nouns gender
by ww (Archbishop) on Nov 08, 2006 at 16:48 UTC

    Not quite. If the first answer is wrong, this code does NOT give the correct answer, as OP requested, but gets stuck in a loop.

    C:\perl germ.pl Reisebus: das Wrong Reisebus: den Wrong Reisebus: the Wrong Reisebus: der Rigth Reisebus: Wrong Reisebus: Terminating on signal SIGINT(2)

    No downvote for that; just a note; but please see the tenor of xorl 's reply and the very explicit admonitions from others, (including /me, below)... and consider the "fish" story -- " Teach a man to fish...."

Re^2: german nouns gender
by imp (Priest) on Nov 08, 2006 at 17:00 UTC
    When offering instruction to someone who is obviously new to perl it would be best to take the opportunity to teach them. Whether that is done by providing hints, or providing a solid solution is of course up to the author.

    The solution you provided is close to what he was asking for, but it would have been better to use strict and warnings to encourage good habits, and it would be good to offer links to the syntax/idioms that might be unfamiliar to the original poster. For example, he might not be familiar with the ternary operator or the autoflush variable