> Hi List, > > I have a script that takes input ( Formatted: +1########## ). What it does wi > th the input is read thru a database table and try to find a match. Here is a > n example to help clarify this: >
Here is the cleaned up version of what you're doing -- since I don't have your database I'm using a <DATA> section to simulate it. I've cleaned up some of the regexps to be a little tidier Also, you had a subtle non-effectual bug -- because the row from the database had an embedded "+" in it, the regexp inside your match in the while loop ( $uri_to =~ m/(\+$data[0])/ was evaluated as \++1314898... Which meant "optionally put a plus in front of this number..." I think it is cleaner to explicitly do the substitution in the target string, although I'm sure there is a way to force it with an eval() (I'm a big fan of Explicit and Clear vs. Subtle and Confusing ) .............................. BEGIN PERL PROGRAM ...................... #!/usr/bin/perl # file: /tmp/dialplan.pl use strict; use warnings; use DBI; # my @DBIconn = qw(DBI:mysql:ser:bunsen.netlogic.net ser ftff39b); #my $dbh = DBI->connect(@DBIconn) or # die "Couldn't connect to database: " . DBI->errstr; my $uri_to ; #= $ENV{'SIP_HF_TO'}; print "Type in a qualified number:\n"; $uri_to = <>; chomp $uri_to; #$uri_to =~ m/(\+1\d\d\d\d\d\d\d\d\d\d)/ ; if ( $uri_to =~ m/(\+1\d{10})/) { while (<DATA>) { my ($plan, $destination) = split /::/; if (my ($target) = $uri_to =~ m/(\+$plan)/) { $destination =~ s/__TARGET__/$target/; print "Matches with $destination \n"; last; } else { print "No Match\n"; } } } __DATA__ 15305473410::sip:[EMAIL PROTECTED] 161757789\d{2}::sip:[EMAIL PROTECTED] 131489804[0-7][0-9]::sip:[EMAIL PROTECTED] ............................... END PERL PROGRAM ....................... Now, as to the second part of your questin "Is this a bad idea ...? " My gut (and many years of experience) tells me "putting a big fat database select in the middle of your route selection code is going to be a performance pig". Caching, caching, caching. -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g Computer software consists of only two components: ones and zeros, in roughly equal proportions. All that is required is to sort them into the correct order. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>