* Winter Christian <[EMAIL PROTECTED]> [2004-06-01 16:31]: > Another approach: > > use re 'eval'; > my $re = qr/(\d{4})(??{ $1>$year?'':'x{1000}' })$/; > > Assuming, of course, that $_ never contains a smaller year > number followed by thousand 'x'es. :-)
You can remove that limitation by replacing 'x{1000}' by '(?!)', a zero-width negative lookahead, which *always* fails. Your approach requires multiple regex compilation, too -- the regex returned by your code is compiled in at run time. If you do want to go down that route, I'd rather do it like this: my $re = qr/(\d{4})(?(?{ $1 <= $year })(?!))/; which uses a conditional subexpression (?(cond)if-true), where the condition is a Perl expression (?{ $1 <= $year }), to force failure using the aforementioned (?!), if the condition is true (which means I must test for less-than-or-equal, where you test for greater-than). -- Regards, Aristotle "If you can't laugh at yourself, you don't take life seriously enough."