Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Set operations

by Loops (Curate)
on Dec 02, 2014 at 03:27 UTC ( #1108910=note: print w/replies, xml ) Need Help??


in reply to Set operations

Hola,

Your code actually works okay as long as you enter a number for each input. It's a little confusing because there are no prompts for each number in the set, just a blank line. If you happen to press [ENTER] instead of entering a number at any point, you'll get lots of errors.

You will want to change your code to test every input made by the user to see if it is a valid number, and only add it to the set if so. If it is a bad input, loop around and ask again.

Replies are listed 'Best First'.
Re^2: Set operations
by davido (Cardinal) on Dec 02, 2014 at 03:36 UTC

    Though he's probably not allowed to use CPAN in his course work, it's too bad. Because if he could, he would be able to use IO::Prompt::Tiny or IO::Prompt::Hooked to simplify the prompting for input. In fact, though it's like calling in the artillery when a fly swatter is needed, ExtUtils::MakeMaker is a core module, and comes with the prompt function.

    use ExtUtils::MakeMaker 'prompt'; my $value = prompt "Please enter something.", "asdf"; print "$value\n";

    The first argument is what to say to the user. The second argument is what default to assume if the user just hits enter (or if there's no terminal).


    Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2021-06-25 12:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (136 votes). Check out past polls.

    Notices?