Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re: german nouns gender

by imp (Priest)
on Nov 08, 2006 at 16:37 UTC ( #582911=note: print w/replies, xml ) Need Help??

in reply to german nouns gender

What have you tried so far? Monks tend to offer more help to people who are trying to solve a problem, versus people looking to have the community write their code for them.

Good places to start would be open and split.

The basic flow of the program should be something like this:

  1. Open the file
  2. Read each line, splitting the text into article and noun.
  3. Find the total number of entries
  4. Generate a random number between 1 and the last index of the set
  5. Loop, Printing the noun and testing user input against the article
A few hints:
Open a file:
open my $fh, '<', $filename or die "Failed to open $filename - $!";
Read the file one line at a time:
while (my $line = <$fh>) { # Do something with $line }
Check the number of items in a list (by evaluating a list in scalar context):
my $count = @list;
Get a line of input:
my $answer = <STDIN>;
Update - hint: always use strict and warnings
Always use the following at the top of your script:
use strict; use warnings;
By default perl is extremely forgiving and tries to do what you mean. Sometimes this is desireable, but normally you want perl to be strict and catch the mistakes you make. Save yourself a lot of debugging time by always using both strict and warnings.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://582911]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (6)
As of 2018-03-22 22:40 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (286 votes). Check out past polls.