Ahten has asked for the wisdom of the Perl Monks concerning the following question:
Hey, so I'm fairly new to perl and was experimenting with a random number generator and some other things as a sort of intelligence test, long story short, I didn't make it very far. I'd like to ask the user if they accept the challenge, but also have it loop and ask again for user-input if a non-acceptable answer is entered. Here is the segment of my code where the error "Can't call method "untill" without a package or object reference"
#!usr/bin/perl use strict; use warnings; use diagnostics; my $range = 100; my $random_number = int(rand($range)); my $answer = 0; print "Do you accept this challenge? "; Do { chomp (my $response = <>); if ($response eq 'yes' || 'Yes' || 'YES' || 'y') { $answer = $answer + 1; } elsif ($response eq 'no' || 'No' || 'NO' || 'n') { $answer = $answer + 2; } else { print "Please respond with 'yes' or 'no'\n\n"; } }until $answer > 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: User input check 'Do until' loop
by Eliya (Vicar) on Mar 13, 2012 at 12:25 UTC | |
by Ahten (Initiate) on Mar 13, 2012 at 13:04 UTC | |
|
Re: User input check 'Do until' loop
by tobyink (Canon) on Mar 13, 2012 at 13:08 UTC | |
|
Re: User input check 'Do until' loop
by Anonymous Monk on Mar 13, 2012 at 12:29 UTC | |
|
Re: User input check 'Do until' loop
by Anonymous Monk on Mar 13, 2012 at 21:43 UTC |