logo       

Sponsor
FREE Network Mapping Tool for Microsoft® Office Visio® Professional 2007
Don't map your network by hand - let LANsurveyor Exx press for Microsoft Visio Professional 2007 automatically create network diagrams for you!

Regexp code feature: msg#00022

lang.perl.modules.authors

Subject: Regexp code feature

What's the minimum version of Perl needed to reliably exploit the (?{ code }) feature in regexps?

I'm working on a module that I call Net::IP::Match::Regexp which builds and runs regexps that contain simple code blocks. It works great under 5.8.1 on my Mac, but I haven't tested older Perl versions yet.

My code turns these IP ranges (randomly generated)
109.27.190.54/28 => 1
109.61.26.198/24 => 2
180.203.154.195/28 => 3
5.98.198.68/19 => 4
68.238.145.35/29 => 5

into regexps look like this:

my $re = "^(?:0(?:000010101100010110(?{'2'})|1(?:000100111011101001000100100(? {'3'})|10110100(?:011011101111100011(?{'5'})|11110100011010(? {'4'}))))|1011010011001011100110101100(?{'1'}))";


It's used in this context, pulling the code values out via $^R:

sub match_ip
{
my ($ip,$re) = @_;

local $^R;
use re 'eval';
unpack("B32", pack("C4", split(/\./, $ip))) =~ /$re/;
return $^R;
}

Thanks much,
Chris
--
Chris Dolan, Software Developer, Clotho Advanced Media Inc.
608-294-7900, fax 294-7025, 1435 E Main St, Madison WI 53703

Clotho Advanced Media, Inc. - Creators of MediaLandscape Software (http://www.media-landscape.com/) and partners in the revolutionary Croquet project (http://www.opencroquet.org/)







Only community members can participate in forum threads. You must Register or log in to contribute.

<Prev in Thread] Current Thread [Next in Thread>
Sponsor
FREE Network Mapping Tool for Microsoft® OfficeVisio Professional 2007
Don't map your network by hand - let LANsurveyor Express for Microsoft Visio Professional 2007
automatically create network diagrams for you!
Google Custom Search

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation

Home | sitemap | advertise | OSDir is an inevitable website. super tiny logo