Mike Schilli's Friendly Neighborhood Perl Shop

Home
USArundbrief.com
Resume
CPAN Modules
Articles in English
Articles in German
Mike's Script Archive
English-Japanese Translation Trainer
Adventures with O'Reilly's Safari
10 Easy Steps to Become a California Driver
Unofficial perlmonks.com IRC Channel
My Collection of Outage Pages
Prisma (Computer Club Deutschland)
Mike's Monologues
Mike's Script Archive: Pick.pm

Pick -- A module to ask for user input


NAME

    Pick -- A module to ask for user input


DOWNLOAD

Pick.pm


SYNOPSIS

    use Pick;
        # "File name [index.html]>"
    Pick::single("File name", "index.html");
        # "[1] apple
        #  [2] pear
        #  [3] pineapple
        #  Pick a fruit [3]> "
    Pick::list("Pick a fruit", ["apple", "pear", "pineapple"], 3);


DESCRIPTION

Pick asks for user input on the command line. It either collects a single answer or lets the user pick from a list.

Both functions single() and list() take default values, which they will return if the user just hits the Return key without providing input.


EXAMPLES


Collect a single value from the user:
    use Pick;
    Pick::single("File name", "index.html");

will display the following:

    File name [index.html]>

and wait for input. If the user hits Return, it will return "index.html" if the user types in a text string and hits return, the text string will be returned, not including the trailing newline.

    use Pick;
    Pick::list("Pick a fruit", ["apple", "pear", "pineapple"], 3);

will display the following:

    [1] apple
    [2] pear
    [3] pineapple
    Pick a fruit [3]>

If the user just hits Enter, ``pineapple'' (the default value) will be returned. Note that 3 marks the 3rd element of the list, and is not an index value into the array.

If the user enters 1, 2 or 3, the corresponding text string ("apple", "pear", "pineapple" will be returned by Pick::list().


LEGALESE

Copyright 2002 by Mike Schilli, all rights reserved. This program is free software, you can redistribute it and/or modify it under the same terms as Perl itself.


AUTHOR

2002, Mike Schilli <m@perlmeister.com>


Latest update: 20-Oct-2013