… | |
… | |
9 | |
9 | |
10 | our $VERSION = $IO::AIO::VERSION; |
10 | our $VERSION = $IO::AIO::VERSION; |
11 | |
11 | |
12 | Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version"); |
12 | Getopt::Long::Configure ("bundling", "no_ignore_case", "require_order", "auto_help", "auto_version"); |
13 | |
13 | |
14 | my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles); |
14 | my ($opt_silent, $opt_print0, $opt_stat, $opt_nodirs, $opt_nofiles, $opt_grep); |
15 | |
15 | |
16 | GetOptions |
16 | GetOptions |
17 | "quiet|q" => \$opt_silent, |
17 | "quiet|q" => \$opt_silent, |
18 | "print0|0" => \$opt_print0, |
18 | "print0|0" => \$opt_print0, |
19 | "stat|s" => \$opt_stat, |
19 | "stat|s" => \$opt_stat, |
20 | "dirs|d" => \$opt_nofiles, |
20 | "dirs|d" => \$opt_nofiles, |
21 | "files|f" => \$opt_nodirs, |
21 | "files|f" => \$opt_nodirs, |
|
|
22 | "grep|g=s" => \$opt_grep, |
22 | or die "Usage: try $0 --help"; |
23 | or die "Usage: try $0 --help"; |
23 | |
24 | |
24 | @ARGV = "." unless @ARGV; |
25 | @ARGV = "." unless @ARGV; |
25 | |
26 | |
|
|
27 | $opt_grep &&= qr{$opt_grep}s; |
|
|
28 | |
26 | sub printfn { |
29 | sub printfn { |
27 | my ($prefix, $files, $suffix) = @_; |
30 | my ($prefix, $files, $suffix) = @_; |
28 | |
31 | |
|
|
32 | if ($opt_grep) { |
|
|
33 | @$files = grep "$prefix$_" =~ $opt_grep, @$files; |
|
|
34 | } |
|
|
35 | |
29 | if ($opt_print0) { |
36 | if ($opt_print0) { |
30 | print map "$prefix$_$suffix\0", @$files; |
37 | print map "$prefix$_$suffix\0", @$files; |
31 | } elsif (!$opt_silent) { |
38 | } elsif (!$opt_silent) { |
32 | print map "$prefix$_$suffix\n", @$files; |
39 | print map "$prefix$_$suffix\n", @$files; |
33 | } |
40 | } |