-
Notifications
You must be signed in to change notification settings - Fork 1
/
browse_records.0
28 lines (23 loc) · 914 Bytes
/
browse_records.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
#########################################################
# 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 ( style => 'Korn' );
if (@ARGV != 2 and @ARGV != 3) {
# Could also use Getopt:* module for option parsing
die "Usage: $0 fieldnum filename [delimiter]" ;
}
( $field, $file, $delim) = @ARGV ;
if ( ! defined $delim ) {
$delim='[\040\t]+' # SP/TAB sequences
}
$field-- ; # 2->1, 1->0, etc., for 0-based indexing
foreach ( `cat "$file"` ) {
# field is the key in the hash, value is entire record
$f2r{ (split /$delim/, $_)[ $field ] } = $_ ;
}
# Show specified fields in menu, and display associated records
select $record ( sort keys %f2r ) {
print "$f2r{$record}" ;
}