I have script getfiles.pl with code like that
my %options;
getopts("r:", \%options);
...
$regex = qr($options{r});
foreach (@files){
my $filepath = $_->[0];
if ($filepath =~ $regex){
push @matched, $filepath;
}
}
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("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;
}
}
but the subroutine is not good, ask some advice
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.