| 1 |
Shell/POSIX/Select version 0.07 |
| 2 |
=============================== |
| 3 |
|
| 4 |
INSTALLATION |
| 5 |
|
| 6 |
To install this module type the following: |
| 7 |
|
| 8 |
perl Makefile.PL |
| 9 |
make test |
| 10 |
make install |
| 11 |
|
| 12 |
DEPENDENCIES |
| 13 |
|
| 14 |
This module requires these other modules and libraries: |
| 15 |
|
| 16 |
File::Spec::Functions |
| 17 |
Text::Balanced |
| 18 |
Filter::Simple |
| 19 |
|
| 20 |
================================================================== |
| 21 |
|
| 22 |
NAME |
| 23 |
|
| 24 |
Shell::POSIX::Select - The POSIX Shell's "select" loop for Perl |
| 25 |
|
| 26 |
PURPOSE |
| 27 |
|
| 28 |
This module implements the "select" loop of the "POSIX" shells |
| 29 |
(Bash, Korn, and derivatives) for Perl. That loop is unique in |
| 30 |
two ways: it's by far the friendliest feature of any UNIX shell, |
| 31 |
and it's the *only* UNIX shell loop that's missing from the Perl |
| 32 |
language. Until now! |
| 33 |
|
| 34 |
SYNOPSIS |
| 35 |
|
| 36 |
NOTE: In the following, the enclosing square brackets (not |
| 37 |
typed) identify optional elements, and vertical bars indicate |
| 38 |
mutually-exclusive choices: |
| 39 |
|
| 40 |
select [[my|local|our<]> scalar_var] ( [LIST] ) { [CODE] } |
| 41 |
|
| 42 |
The required elements are the keyword "select", the *parentheses*, |
| 43 |
and the *curly braces*. See "SYNTAX" for details. |
| 44 |
|
| 45 |
ELEMENTARY EXAMPLE |
| 46 |
|
| 47 |
ship2me2.plx |
| 48 |
|
| 49 |
use Shell::POSIX::Select qw($Heading $Prompt); |
| 50 |
|
| 51 |
$Heading='Select a Shipper' ; |
| 52 |
$Prompt='Enter Vendor Number: ' ; |
| 53 |
|
| 54 |
select $shipper ( 'UPS', 'FedEx' ) { |
| 55 |
print "\nYou chose: $shipper\n"; |
| 56 |
last; |
| 57 |
} |
| 58 |
ship ($shipper, $ARGV[0]); # prints confirmation message |
| 59 |
|
| 60 |
|
| 61 |
OUTPUT |
| 62 |
|
| 63 |
ship2me2.plx '42 hemp toothbrushes' |
| 64 |
|
| 65 |
*Select a Shipper* |
| 66 |
|
| 67 |
1) UPS 2) FedEx |
| 68 |
|
| 69 |
Enter Vendor Number: 2 |
| 70 |
You chose: FedEx |
| 71 |
|
| 72 |
Your order has been processed. Thanks for your business! |
| 73 |
|
| 74 |
BENEFITS |
| 75 |
|
| 76 |
What's so great about this loop? It automates the generation of a |
| 77 |
numbered menu of choices, prompts for a choice, proofreads that |
| 78 |
choice and complains if it's invalid (at least in this enhanced |
| 79 |
implementation), and executes a code-block with a variable set to |
| 80 |
the chosen value. That saves a lot of coding for interactive |
| 81 |
programs -- especially if the menu consists of many values! |
| 82 |
|
| 83 |
The benefit of bringing this loop to Perl is that it obviates the |
| 84 |
need for future programmers to reinvent the *Choose-From-A-Menu* |
| 85 |
wheel. |
| 86 |
|
| 87 |
EXPORTS: Default |
| 88 |
|
| 89 |
$Reply |
| 90 |
|
| 91 |
This variable is "local"ized to each "select" loop, and provides |
| 92 |
the menu-number of the most recent valid selection. |
| 93 |
|
| 94 |
EXPORTS: Optional |
| 95 |
|
| 96 |
$Heading |
| 97 |
$Prompt |
| 98 |
$Eof |
| 99 |
|
| 100 |
SCRIPTS |
| 101 |
|
| 102 |
browse_images |
| 103 |
browse_jpeg |
| 104 |
browse_records |
| 105 |
delete_file |
| 106 |
lc_filename |
| 107 |
long_listem |
| 108 |
menu_ls |
| 109 |
order |
| 110 |
perl_man |
| 111 |
pick |
| 112 |
pick_file |
| 113 |
|
| 114 |
AUTHOR |
| 115 |
|
| 116 |
Tim Maher |
| 117 |
|
| 118 |
MAINTAINER |
| 119 |
|
| 120 |
Martin Thurn |
| 121 |
[email protected] |
| 122 |
|
| 123 |
ACKNOWLEDGEMENTS |
| 124 |
|
| 125 |
I probably never would have even attempted to write this module if |
| 126 |
it weren't for the provision of Filter::Simple by Damian Conway, |
| 127 |
which I ruthlessly exploited to make a hard job easy. |
| 128 |
|
| 129 |
*The Damian* also gave useful tips during the module's |
| 130 |
development, for which I'm grateful. |
| 131 |
|
| 132 |
I *definitely* wouldn't have ever written this module, if I hadn't |
| 133 |
found myself writing a chapter on *Looping* for my upcoming |
| 134 |
Manning Publications book, and once again lamenting the fact that |
| 135 |
the most friendly Shell loop was missing from Perl. In a fit of |
| 136 |
zeal, I decided to rectify that oversight! 8-} |
| 137 |
|
| 138 |
For more examples of how this loop can be used in Perl programs, |
| 139 |
watch for my upcoming book, *Minimal Perl: for Shell Users and |
| 140 |
Programmers* (see <http://teachmeperl.com/mp4sh.html>) in early |
| 141 |
fall, 2003. |
| 142 |
|
| 143 |
SEE ALSO |
| 144 |
|
| 145 |
man ksh # on UNIX or UNIX-like systems |
| 146 |
|
| 147 |
man bash # on UNIX or UNIX-like systems |
| 148 |
|
| 149 |
DON'T SEE ALSO |
| 150 |
|
| 151 |
perldoc -f select, which has nothing to do with this module (the |
| 152 |
names just happen to match up). |
| 153 |
|
| 154 |
LICENSE |
| 155 |
|
| 156 |
Copyright (C) 2002-2003, Timothy F. Maher. All rights reserved. |
| 157 |
|
| 158 |
This module is free software; you can redistribute it and/or |
| 159 |
modify it under the same terms as Perl itself. |