vincentaxhe has asked for the wisdom of the Perl Monks concerning the following question:
I run getfiles.pl -r 'python' filelist to filter filepath containing 'python' but I also want to run like getfiles.pl -e '-d' listfile to get files which are dirs or getfiles.pl -e '-s > 100' filelist and more such as -t -M.my %options; getopts("r:", \%options); ... $regex = qr($options{r}); foreach (@files){ my $filepath = $_->[0]; if ($filepath =~ $regex){ push @matched, $filepath; } }
but the subroutine is not good, ask some advicemy %options; getopts("e:", \%options); ... $wanted = qr($options{e}); sub getwanted(&@){ my ($wanted, $file) return 1 if $wanted->($file) ... } foreach (@files){ $filepath = $_->[0]; if (getwanted $wanted $filepath){ push @matched, $filepath; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: use -d -t -s as script args
by ikegami (Patriarch) on Jun 21, 2024 at 16:09 UTC | |
by vincentaxhe (Scribe) on Jun 21, 2024 at 19:35 UTC | |
by Anonymous Monk on Jun 29, 2024 at 00:05 UTC |