in reply to Re: Appropriately assigning times to variables
in thread Appropriately assigning times to variables

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on Re^2: Appropriately assigning times to variables

Replies are listed 'Best First'.
Re^3: Appropriately assigning times to variables
by blazar (Canon) on May 04, 2007 at 10:52 UTC
    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?

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^3: Appropriately assigning times to variables
by Moron (Curate) on May 03, 2007 at 10:23 UTC
    I've now commented the code in Filter to show the functional purpose of each piece of filtering (see updated version above above).
    __________________________________________________________________________________

    ^M Free your mind!