in reply to Longest Matching URL
untested:
my @candidates = qw( http://www.someplace.com/foo http://www.someplace.com/foo/bar http://www.someplace.else.com/foo ); my $target = 'http://www.someplace.com/foo/fighter/index.html'; my %leader = ( uri => '', length => 0 ); foreach my $candidate (@candidates) { if( $target =~ /^$candidate/ ) { if( length($candidate) > $leader{length} ) { @leader{'uri','length'} = ($candidate,length($candidate)); } } } if( $leader{uri} ) { print $leader{uri},',',substr($target,$leader{length}); } else { print "no matches" }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Longest Matching URL
by marceus (Initiate) on Mar 20, 2002 at 19:58 UTC |
In Section
Seekers of Perl Wisdom