Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

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.


Comment on Re: german nouns gender
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://582911]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-07-31 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (254 votes), past polls