Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should use <a href="http://search.cpan.org/perldoc?DateTime" rel="nofollow"><code>DateTime</code></a> if available, but if not, then the below should do. Really, at this stage, you should rolling your own date logic, but it still is pretty easy using <em>core</em> module <a href="http://search.cpan.org/perldoc?POSIX#mktime" rel="nofollow"><code>POSIX</code></a>.</p> <pre><code>use strict; use warnings; use POSIX (); # get a list of month symbols my @mons = qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/; # Create a symbol -&gt; number table my %num_for = do { my $mon = 0; map { $_ =&gt; $mon++ } @mons; }; # Create the alternation of months # Create line regex my $time_rex = qr/ (${\join( '|', @mons )}) \s+ 0? (\d+) \s+ (\d{2}) : (\d{2}) : (\d{2}) \s+ # I made the tz optional to handle scalar( localtime ) (?: (\p{alpha}+) \s+ )? (\d{4}) /x ; ... # Convienience function sub get_time_value { # parse date string return unless my @fields = ( shift =~ /$time_rex/ ); # get numerical month $fields[0] = $num_for{ $fields[0] }; # perl year kludge $fields[-1] -= 1900; return wantarray ? @fields[ 4, 3, 2, 1, 0, 6, 5 ] : POSIX::mktime( @fields[ 4, 3, 2, 1, 0, 6 ] ) ; } sub days_prior_to_now { return unless defined( my $days_prior = shift ); return time unless $days_prior; $days_prior = - $days_prior if $days_prior &lt; 0; my $date_string = scalar( localtime ); return unless my ( $sec, $min, $hr, $day, $mon, $year, $tz ) = get_time_value( $date_string ) ; return POSIX::mktime( $sec, $min, $hr, $day - $days_prior, $mon, $year ); } sub is_100_days_before_now { my $a_string = shift; croak "Could not parse '$a_string'!" unless my $a_value = get_time_value( $a_string ); return $a_value &lt; days_prior_to_now( 100 ); } if ( is_100_days_before_now( $a )) { ... } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload