in reply to Verifying a date

String eval is considered a bad practice. Block eval is safe, and if you don't like it, use any of the try/catch modules available for a more mainstream look.

#!/usr/bin/perl use warnings; use strict; use Time::Piece; sub validate_date { my ($date) = @_; return eval { $date eq Time::Piece->strptime($date, '%m.%d.%y')->s +trftime('%m.%d.%y') } } use Test::More tests => 5; ok validate_date('02.28.19'); ok ! validate_date('02.32.19'); ok ! validate_date('02.29.19'); ok validate_date('02.29.16'); ok ! validate_date('02.30.16');

The eq is needed because 02.29.19 is parsed without an error by Time::Piece, returning 03.01.19 when formatted back to a string.

Update: It passes Corion's test cases correctly.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]