[From nobody Mon Aug 2 21:29:00 2004 Return-Path: <fwp-return-3566-pagaltzis=gmx.de@perl.org> X-Flags: 0000 Delivered-To: GMX delivery to pagaltzis@gmx.de Received: from pop.gmx.net [213.165.64.20] by localhost with POP3 (fetchmail-6.2.5) for ap@localhost (single-drop); Tue, 01 Jun 2004 16:48:16 +0200 (CEST) Received: (qmail 1361 invoked by uid 65534); 1 Jun 2004 14:47:33 -0000 Received: from onion.develooper.com (HELO onion.perl.org) (63.251.223.166) by mx0.gmx.net (mx001) with SMTP; 01 Jun 2004 16:47:33 +0200 Received: (qmail 24193 invoked by uid 1005); 1 Jun 2004 14:47:07 -0000 Mailing-List: contact fwp-help@perl.org; run by ezmlm Precedence: bulk List-Post: <mailto:fwp@perl.org> List-Help: <mailto:fwp-help@perl.org> List-Unsubscribe: <mailto:fwp-unsubscribe@perl.org> List-Subscribe: <mailto:fwp-subscribe@perl.org> Delivered-To: mailing list fwp@perl.org Received: (qmail 24178 invoked from network); 1 Jun 2004 14:47:07 -0000 Delivered-To: fwp@perl.org X-Spam-Status: No, hits=0.0 required=7.0 tests= X-Spam-Check-By: la.mx.develooper.com X-Authenticated: #163624 Date: Tue, 1 Jun 2004 16:47:02 +0200 From: "A. Pagaltzis" <pagaltzis@gmx.de> To: fwp@perl.org Subject: Re: Regular expression for years after a given one Message-ID: <20040601144702.GB20729@klangraum> Mail-Followup-To: fwp@perl.org References: <5F717E222D4ADB4EA8A6EAFA402ADCF998A1@platinum.coc-ag.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <5F717E222D4ADB4EA8A6EAFA402ADCF998A1@platinum.coc-ag.net> User-Agent: Mutt/1.4.2.1i X-Spam-Rating: onion.develooper.com 1.6.2 0/1000/N X-GMX-Antivirus: -1 (not scanned, may not use virus scanner) X-GMX-Antispam: 0 (Mail was not recognized as spam) * Winter Christian <Christian.Winter@coc-ag.de> [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." ]