My only concern is that common man does not easily understand the code in the Sub Filter
Depends on your definition of "common man". If the latter comprises one who does not know Perl at all, then your concern is justified. But then I don't know how it could be put in a form that is understandable to the "common man". Otherwise, anyone with basic Perl knowledge should not have any problem with it.
Let's check it together:
my %opt = @_;
Filter expects a list of key-value pairs as arguments, that will be put into a %opt hash. This is a common way to "fake" named arguments. Any problem with this?
( -d "$opt{ dir }/$_" ) # is a directory
-d is a test operator that should be well known and is documented in perldoc -f -X. It tests a string that interpolates some variables in an obvious way. Any problem with this?
&& !/^\./ # is also not hidden/special
Use of short circuiting &&: this expression is only evaluated if the former returned a true value. (The same goes on for the following lines, so I won't repeat that.) Any problem with this?
After the && you have a negated pattern match: you are checking that $_ doesn't match the expression. Any problem with this?
&& /(\d{4}_\d{2}_\d{2}_\d{2})/
# contains date/hour
Ditto as above, except that the pattern is slightly more complex: specifically you're searching a string comprising of 4 digits, a underscore, 2 digits, a underscore, 2 digits, a underscore, and last, other 2 digits. And you capture that string. Any problem with this?
&& ($opt{ now } gt $1 ) # that is in the past
You now compare as strings the value of $1, i.e. the string captured above, with another one, supposedly in the same format. Since these strings represent a time specification in an obvious manner, the string inequality also represents a chronological one. Any problem with this? |