in reply to Re: Organising lots of simple regexes
in thread Organising lots of simple regexes
Thanks all for your ideas. As an alternate way of writing this, so I don't have to have lots of subroutine refs in a big hash structure, I'm now thinking of doing something like this:</code>
use strict; package Our::Redirects; sub www_theirsite_com { my $url = shift; # and transform url here however } # allow for alt domain names *www_theirsite_co_uk = \&www_theirsite_com; package main; use URI; while ( <> ) { my $uri = URI->new($_) or die "Can't parse URI"; my $func = lc( $uri->host() ); $func =~ tr/.-/_/; if ( defined &{ "Our::Redirects::$func" } ) { &{ \&{ "Our::Redirects::$func" } }($_); } }
This seems to me to have the advantages of a hash-type construct - i.e. straight-thru mapping - but slightly sugary syntax, particularly for some of the cases which aren't quite as simple as the ones I suggested. Does this seem like a reasonable way to go?
Thanks again
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Re: Organising lots of simple regexes
by hardburn (Abbot) on Jan 27, 2004 at 16:14 UTC |