-
Notifications
You must be signed in to change notification settings - Fork 1
/
max_columns_1.0
49 lines (37 loc) · 1.49 KB
/
max_columns_1.0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#########################################################
# Sample Program for Perl Module "Shell::POSIX::Select" #
# tim@TeachMePerl.com (888) DOC-PERL (888) DOC-UNIX #
# Copyright 2002-2003, Tim Maher. All Rights Reserved #
#########################################################
use Shell::POSIX::Select qw($Heading $Prompt $Eof $MaxColumns) ;
# following avoids used-only once warning
my ($type, $format) ;
# Would be more Perlish to associate choices with options
# using a Hash, but this approach demonstrates $Reply variable
@formats = ( 'regular', 'long' ) ;
@fmt_opt = ( '', '-l' ) ;
@types = ( 'only non-hidden', 'all files' ) ;
@typ_opt = ( '', '-a' , ) ;
print "** LS-Command Composer **\n\n" ;
$Heading="\n**** Style Menu ****" ;
$Prompt= "Choose listing style:" ;
$MaxColumns = 1;
OUTER:
select $format ( @formats ) {
$user_format=$fmt_opt[ $Reply - 1 ] ;
$Heading="\n**** File Menu ****" ;
$Prompt="Choose files to list:" ;
$MaxColumns = 1;
select $type ( @types ) { # ^D restarts OUTER
$user_type=$typ_opt[ $Reply - 1 ] ;
last OUTER ; # leave loops once final choice obtained
}
}
$Eof and exit ; # handle ^D to OUTER
# Now construct user's command
$command="ls $user_format $user_type" ;
# Show command, for educational value
warn "\nPress <ENTER> to execute \"$command\"\n" ;
# Now wait for input, then run command
defined <> or print "\n" and exit ;
system $command ; # finally, run the command