| 1 |
|
| 2 |
$Prompt='Outer'; |
| 3 |
|
| 4 |
# Code generated by Shell::POSIX::Select v0.09, by tim(AT)TeachMePerl.com |
| 5 |
# NOTA BENE: Line 1 of this segment must start with {, so user can LABEL it |
| 6 |
{ # **** NEW WRAPPER SCOPE FOR SELECTLOOP #1 **** |
| 7 |
$Shell::POSIX::Select::DEBUG > 1 and 1 == 1 and |
| 8 |
warn "LINE NUMBER FOR START OF USER CODE_BLOCK IS: ", __LINE__, "\n"; |
| 9 |
_SEL_LOOP1: { # **** NEW SCOPE FOR SELECTLOOP #1 **** |
| 10 |
|
| 11 |
# critical for values's contents to be resolved in user's scope |
| 12 |
local @Shell::POSIX::Select::looplist=(1); |
| 13 |
local $Shell::POSIX::Select::num_values=@Shell::POSIX::Select::looplist; |
| 14 |
|
| 15 |
$Shell::POSIX::Select::DEBUG > 4 and do { |
| 16 |
warn "ARRAY VALUES ARE: @Shell::POSIX::Select::looplist\n"; |
| 17 |
warn "NUM VALUES is $Shell::POSIX::Select::num_values\n"; |
| 18 |
warn "user-program debug level is $Shell::POSIX::Select::U_WARN\n"; |
| 19 |
}; |
| 20 |
my $var; # LOOP-VAR DECLARATION REQUESTED (perhaps by default) # loop-var declaration appears here |
| 21 |
|
| 22 |
; |
| 23 |
local ( |
| 24 |
$Shell::POSIX::Select::Prompt[1], |
| 25 |
$Shell::POSIX::Select::menu |
| 26 |
) = |
| 27 |
Shell::POSIX::Select::make_menu( |
| 28 |
$Shell::POSIX::Select::Heading || "", |
| 29 |
$Shell::POSIX::Select::Prompt || "" , # Might be overridden in make_menu |
| 30 |
@Shell::POSIX::Select::looplist |
| 31 |
); |
| 32 |
|
| 33 |
# no point in prompting a pipe! |
| 34 |
local $Shell::POSIX::Select::do_prompt[1] = (-t) ? 1 : 0 ; |
| 35 |
0 > 2 and warn "do_prompt is $Shell::POSIX::Select::do_prompt[1]\n"; |
| 36 |
if ( defined $Shell::POSIX::Select::menu ) { # No list, no iterations! |
| 37 |
while (1) { # for repeating prompt for selections |
| 38 |
# localize, so I don't have to reset for |
| 39 |
# outer loop on exit from inner |
| 40 |
local ($Reply); |
| 41 |
while (1) { # for validating user's input |
| 42 |
local $Shell::POSIX::Select::bad = 0; |
| 43 |
|
| 44 |
# local decl suppresses newline on prompt when -l switch turned on |
| 45 |
{ |
| 46 |
local $\; |
| 47 |
if ($Shell::POSIX::Select::do_prompt[1]) { |
| 48 |
|
| 49 |
# When transferring from INNER to OUTER loop, |
| 50 |
# extra NL before prompt is visually desirable |
| 51 |
|
| 52 |
if ( $Shell::POSIX::Select::_extra_nl) { |
| 53 |
print STDERR "\n\n"; |
| 54 |
$Shell::POSIX::Select::_extra_nl=0; |
| 55 |
} |
| 56 |
print STDERR |
| 57 |
"$Shell::POSIX::Select::menu\n$Shell::POSIX::Select::Prompt[1] "; |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
# $Shell::POSIX::Select::do_prompt=0; |
| 62 |
# constant prompting depends on style |
| 63 |
$Shell::POSIX::Select::do_prompt[1]= 0; |
| 64 |
|
| 65 |
if ( $Shell::POSIX::Select::dump_data ) { |
| 66 |
$Reply = undef; |
| 67 |
# dump filtered source for comparison against expected |
| 68 |
print STDERR "copacetic |
| 69 |
"; # ensure some output, and flush pending |
| 70 |
exit 222; # code for graceful, expected, early exit |
| 71 |
} |
| 72 |
else { |
| 73 |
# $^W=0; |
| 74 |
# warn "Waiting for input"; |
| 75 |
$Eof=0; |
| 76 |
$Reply = <STDIN>; |
| 77 |
# warn "Got input"; |
| 78 |
# $^W=1; |
| 79 |
|
| 80 |
if ( !defined( $Reply ) ) { |
| 81 |
defined "" and "" ne "" and print STDERR ""; |
| 82 |
|
| 83 |
# need to undef loop var; user may check it! |
| 84 |
undef $var; |
| 85 |
|
| 86 |
# last Shell::POSIX::Select::_SEL_LOOP1; # Syntax error! |
| 87 |
# If returning to outer loop, show the prompt for it |
| 88 |
# warn "User hit ^D"; |
| 89 |
if ( 1 > 1 and -t ) { # reset prompting for outer loop |
| 90 |
$Shell::POSIX::Select::do_prompt[1-1] = 1; $Shell::POSIX::Select::_extra_nl=1; |
| 91 |
} |
| 92 |
0 > 2 and warn "Lasting out of _SEL_LOOP1\n"; |
| 93 |
$Eof=1; |
| 94 |
last _SEL_LOOP1; |
| 95 |
} |
| 96 |
!defined $Reply and die "REPLY accessed, while undefined"; |
| 97 |
chomp $Reply; |
| 98 |
|
| 99 |
# undo emboldening of user input |
| 100 |
defined "" and "" ne "" and print STDERR ""; |
| 101 |
|
| 102 |
#print STDERR "$Shell::POSIX::Select::menu\n$Shell::POSIX::Select::Prompt "; |
| 103 |
if ( $Reply eq "" ) { # interpreted as re-print menu request |
| 104 |
# Empty input is legit, means redisplay menu |
| 105 |
$Shell::POSIX::Select::U_WARN > 1 and warn "\tINPUT IS: empty\n"; |
| 106 |
$Shell::POSIX::Select::bad = $Shell::POSIX::Select::do_prompt[1] = 1; |
| 107 |
} |
| 108 |
elsif ( $Reply =~ /\D/ ) { # shouldn't be any non-digit! |
| 109 |
$Shell::POSIX::Select::U_WARN > 0 |
| 110 |
and warn "\tINPUT CONTAINS NON-DIGIT: '$Reply'\n"; |
| 111 |
$Shell::POSIX::Select::bad = 1; # Korn and Bash shell just ignore this case |
| 112 |
} |
| 113 |
elsif ( $Reply < 1 or $Reply > $Shell::POSIX::Select::num_values ) { |
| 114 |
$Shell::POSIX::Select::U_WARN > 0 |
| 115 |
and warn |
| 116 |
"\t'$Reply' IS NOT IN RANGE: 1 - $Shell::POSIX::Select::num_values\n"; |
| 117 |
$Shell::POSIX::Select::bad = 1; # Korn and Bash shell just ignore this case |
| 118 |
} |
| 119 |
|
| 120 |
# warn "BAD is now: $Shell::POSIX::Select::bad"; |
| 121 |
$Shell::POSIX::Select::bad or |
| 122 |
0 > 2 and warn "About to last out of Reply Validator Loop |
| 123 |
"; |
| 124 |
$Shell::POSIX::Select::bad or last; # REPLY VALIDATOR EXITED HERE |
| 125 |
} # if for validating user input |
| 126 |
} # infinite while for validating user input |
| 127 |
|
| 128 |
$var = $Shell::POSIX::Select::looplist[$Reply - 1]; # set users' variable |
| 129 |
|
| 130 |
# USER'S LOOP-BLOCK BELOW |
| 131 |
warn "inside Outer loop\n"; |
| 132 |
|
| 133 |
$Prompt='Inner'; |
| 134 |
|
| 135 |
# Code generated by Shell::POSIX::Select v0.09, by tim(AT)TeachMePerl.com |
| 136 |
# NOTA BENE: Line 1 of this segment must start with {, so user can LABEL it |
| 137 |
{ # **** NEW WRAPPER SCOPE FOR SELECTLOOP #2 **** |
| 138 |
$Shell::POSIX::Select::DEBUG > 1 and 2 == 1 and |
| 139 |
warn "LINE NUMBER FOR START OF USER CODE_BLOCK IS: ", __LINE__, "\n"; |
| 140 |
_SEL_LOOP2: { # **** NEW SCOPE FOR SELECTLOOP #2 **** |
| 141 |
|
| 142 |
# critical for values's contents to be resolved in user's scope |
| 143 |
local @Shell::POSIX::Select::looplist=(qw (a b) ); |
| 144 |
local $Shell::POSIX::Select::num_values=@Shell::POSIX::Select::looplist; |
| 145 |
|
| 146 |
$Shell::POSIX::Select::DEBUG > 4 and do { |
| 147 |
warn "ARRAY VALUES ARE: @Shell::POSIX::Select::looplist\n"; |
| 148 |
warn "NUM VALUES is $Shell::POSIX::Select::num_values\n"; |
| 149 |
warn "user-program debug level is $Shell::POSIX::Select::U_WARN\n"; |
| 150 |
}; |
| 151 |
my $var2; # LOOP-VAR DECLARATION REQUESTED (perhaps by default) # loop-var declaration appears here |
| 152 |
|
| 153 |
; |
| 154 |
local ( |
| 155 |
$Shell::POSIX::Select::Prompt[2], |
| 156 |
$Shell::POSIX::Select::menu |
| 157 |
) = |
| 158 |
Shell::POSIX::Select::make_menu( |
| 159 |
$Shell::POSIX::Select::Heading || "", |
| 160 |
$Shell::POSIX::Select::Prompt || "" , # Might be overridden in make_menu |
| 161 |
@Shell::POSIX::Select::looplist |
| 162 |
); |
| 163 |
|
| 164 |
# no point in prompting a pipe! |
| 165 |
local $Shell::POSIX::Select::do_prompt[2] = (-t) ? 1 : 0 ; |
| 166 |
0 > 2 and warn "do_prompt is $Shell::POSIX::Select::do_prompt[2]\n"; |
| 167 |
if ( defined $Shell::POSIX::Select::menu ) { # No list, no iterations! |
| 168 |
while (1) { # for repeating prompt for selections |
| 169 |
# localize, so I don't have to reset for |
| 170 |
# outer loop on exit from inner |
| 171 |
local ($Reply); |
| 172 |
while (1) { # for validating user's input |
| 173 |
local $Shell::POSIX::Select::bad = 0; |
| 174 |
|
| 175 |
# local decl suppresses newline on prompt when -l switch turned on |
| 176 |
{ |
| 177 |
local $\; |
| 178 |
if ($Shell::POSIX::Select::do_prompt[2]) { |
| 179 |
|
| 180 |
# When transferring from INNER to OUTER loop, |
| 181 |
# extra NL before prompt is visually desirable |
| 182 |
|
| 183 |
if ( $Shell::POSIX::Select::_extra_nl) { |
| 184 |
print STDERR "\n\n"; |
| 185 |
$Shell::POSIX::Select::_extra_nl=0; |
| 186 |
} |
| 187 |
print STDERR |
| 188 |
"$Shell::POSIX::Select::menu\n$Shell::POSIX::Select::Prompt[2] "; |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
# $Shell::POSIX::Select::do_prompt=0; |
| 193 |
# constant prompting depends on style |
| 194 |
$Shell::POSIX::Select::do_prompt[2]= 0; |
| 195 |
|
| 196 |
if ( $Shell::POSIX::Select::dump_data ) { |
| 197 |
$Reply = undef; |
| 198 |
# dump filtered source for comparison against expected |
| 199 |
print STDERR "copacetic |
| 200 |
"; # ensure some output, and flush pending |
| 201 |
exit 222; # code for graceful, expected, early exit |
| 202 |
} |
| 203 |
else { |
| 204 |
# $^W=0; |
| 205 |
# warn "Waiting for input"; |
| 206 |
$Eof=0; |
| 207 |
$Reply = <STDIN>; |
| 208 |
# warn "Got input"; |
| 209 |
# $^W=1; |
| 210 |
|
| 211 |
if ( !defined( $Reply ) ) { |
| 212 |
defined "" and "" ne "" and print STDERR ""; |
| 213 |
|
| 214 |
# need to undef loop var; user may check it! |
| 215 |
undef $var2; |
| 216 |
|
| 217 |
# last Shell::POSIX::Select::_SEL_LOOP2; # Syntax error! |
| 218 |
# If returning to outer loop, show the prompt for it |
| 219 |
# warn "User hit ^D"; |
| 220 |
if ( 2 > 1 and -t ) { # reset prompting for outer loop |
| 221 |
$Shell::POSIX::Select::do_prompt[2-1] = 1; $Shell::POSIX::Select::_extra_nl=1; |
| 222 |
} |
| 223 |
0 > 2 and warn "Lasting out of _SEL_LOOP2\n"; |
| 224 |
$Eof=1; |
| 225 |
last _SEL_LOOP2; |
| 226 |
} |
| 227 |
!defined $Reply and die "REPLY accessed, while undefined"; |
| 228 |
chomp $Reply; |
| 229 |
|
| 230 |
# undo emboldening of user input |
| 231 |
defined "" and "" ne "" and print STDERR ""; |
| 232 |
|
| 233 |
#print STDERR "$Shell::POSIX::Select::menu\n$Shell::POSIX::Select::Prompt "; |
| 234 |
if ( $Reply eq "" ) { # interpreted as re-print menu request |
| 235 |
# Empty input is legit, means redisplay menu |
| 236 |
$Shell::POSIX::Select::U_WARN > 1 and warn "\tINPUT IS: empty\n"; |
| 237 |
$Shell::POSIX::Select::bad = $Shell::POSIX::Select::do_prompt[2] = 1; |
| 238 |
} |
| 239 |
elsif ( $Reply =~ /\D/ ) { # shouldn't be any non-digit! |
| 240 |
$Shell::POSIX::Select::U_WARN > 0 |
| 241 |
and warn "\tINPUT CONTAINS NON-DIGIT: '$Reply'\n"; |
| 242 |
$Shell::POSIX::Select::bad = 1; # Korn and Bash shell just ignore this case |
| 243 |
} |
| 244 |
elsif ( $Reply < 1 or $Reply > $Shell::POSIX::Select::num_values ) { |
| 245 |
$Shell::POSIX::Select::U_WARN > 0 |
| 246 |
and warn |
| 247 |
"\t'$Reply' IS NOT IN RANGE: 1 - $Shell::POSIX::Select::num_values\n"; |
| 248 |
$Shell::POSIX::Select::bad = 1; # Korn and Bash shell just ignore this case |
| 249 |
} |
| 250 |
|
| 251 |
# warn "BAD is now: $Shell::POSIX::Select::bad"; |
| 252 |
$Shell::POSIX::Select::bad or |
| 253 |
0 > 2 and warn "About to last out of Reply Validator Loop |
| 254 |
"; |
| 255 |
$Shell::POSIX::Select::bad or last; # REPLY VALIDATOR EXITED HERE |
| 256 |
} # if for validating user input |
| 257 |
} # infinite while for validating user input |
| 258 |
|
| 259 |
$var2 = $Shell::POSIX::Select::looplist[$Reply - 1]; # set users' variable |
| 260 |
|
| 261 |
# USER'S LOOP-BLOCK BELOW |
| 262 |
warn "inside Inner loop\n"; |
| 263 |
print "$var$var2\n";; |
| 264 |
|
| 265 |
# USER'S LOOP-BLOCK ABOVE |
| 266 |
# Making sure there's colon (maybe |
| 267 |
# even two) after codestring above, |
| 268 |
# in case user omitted after last |
| 269 |
# statement in block. I might add |
| 270 |
# another statement below it someday! |
| 271 |
0 > 2 and warn "At end of prompt-repeating loop |
| 272 |
"; |
| 273 |
} # infinite while for repeating collection of selections |
| 274 |
0 and warn "BEYOND end of prompt-repeating loop |
| 275 |
"; |
| 276 |
} # endif (defined $Shell::POSIX::Select::menu) |
| 277 |
else { |
| 278 |
$Shell::POSIX::Select::DEBUG > 0 and warn "Shell::POSIX::Select: Select Loop #2 has no list, so no iterations\n"; |
| 279 |
|
| 280 |
if ( $Shell::POSIX::Select::dump_data ) { |
| 281 |
$Reply = undef; |
| 282 |
# dump filtered source for comparison against expected |
| 283 |
print STDERR "copacetic |
| 284 |
"; # ensure some output, and flush pending |
| 285 |
exit 222; # code for graceful, expected, early exit |
| 286 |
} |
| 287 |
} |
| 288 |
# return omitted above, to get last expression's value |
| 289 |
# returned automatically, just like shell's version |
| 290 |
|
| 291 |
|
| 292 |
} # **** END NEW SCOPE FOR SELECTLOOP #2 **** |
| 293 |
} # **** END WRAPPER SCOPE FOR SELECTLOOP #2 **** |
| 294 |
# vi:ts=2 sw=2: |
| 295 |
|
| 296 |
warn "outside Inner loop\n";; |
| 297 |
|
| 298 |
# USER'S LOOP-BLOCK ABOVE |
| 299 |
# Making sure there's colon (maybe |
| 300 |
# even two) after codestring above, |
| 301 |
# in case user omitted after last |
| 302 |
# statement in block. I might add |
| 303 |
# another statement below it someday! |
| 304 |
0 > 2 and warn "At end of prompt-repeating loop |
| 305 |
"; |
| 306 |
} # infinite while for repeating collection of selections |
| 307 |
0 and warn "BEYOND end of prompt-repeating loop |
| 308 |
"; |
| 309 |
} # endif (defined $Shell::POSIX::Select::menu) |
| 310 |
else { |
| 311 |
$Shell::POSIX::Select::DEBUG > 0 and warn "Shell::POSIX::Select: Select Loop #1 has no list, so no iterations\n"; |
| 312 |
|
| 313 |
if ( $Shell::POSIX::Select::dump_data ) { |
| 314 |
$Reply = undef; |
| 315 |
# dump filtered source for comparison against expected |
| 316 |
print STDERR "copacetic |
| 317 |
"; # ensure some output, and flush pending |
| 318 |
exit 222; # code for graceful, expected, early exit |
| 319 |
} |
| 320 |
} |
| 321 |
# return omitted above, to get last expression's value |
| 322 |
# returned automatically, just like shell's version |
| 323 |
|
| 324 |
|
| 325 |
} # **** END NEW SCOPE FOR SELECTLOOP #1 **** |
| 326 |
} # **** END WRAPPER SCOPE FOR SELECTLOOP #1 **** |
| 327 |
# vi:ts=2 sw=2: |
| 328 |
|
| 329 |
warn "outside all loops\n"; |