Debian Codegraph @

Ref_Data/sub2.cdump_ref

raw
1
2 sub select_in_sub {
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=defined ((( caller 0 )[3]) and (( caller 0 )[3]) ne "") ? @_ : @ARGV ;
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 ; # NO DECLARATION OF LOOP-VAR REQUESTED # 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 print "$var\n";;
132
133 # USER'S LOOP-BLOCK ABOVE
134 # Making sure there's colon (maybe
135 # even two) after codestring above,
136 # in case user omitted after last
137 # statement in block. I might add
138 # another statement below it someday!
139 0 > 2 and warn "At end of prompt-repeating loop
140 ";
141 } # infinite while for repeating collection of selections
142 0 and warn "BEYOND end of prompt-repeating loop
143 ";
144 } # endif (defined $Shell::POSIX::Select::menu)
145 else {
146 $Shell::POSIX::Select::DEBUG > 0 and warn "Shell::POSIX::Select: Select Loop #1 has no list, so no iterations\n";
147
148 if ( $Shell::POSIX::Select::dump_data ) {
149 $Reply = undef;
150 # dump filtered source for comparison against expected
151 print STDERR "copacetic
152 "; # ensure some output, and flush pending
153 exit 222; # code for graceful, expected, early exit
154 }
155 }
156 # return omitted above, to get last expression's value
157 # returned automatically, just like shell's version
158
159
160 } # **** END NEW SCOPE FOR SELECTLOOP #1 ****
161 } # **** END WRAPPER SCOPE FOR SELECTLOOP #1 ****
162 # vi:ts=2 sw=2:
163
164 }
165
166 @ARGV=1..3;
167 select_in_sub qw(a b) ;