in reply to How do I avoid inserting duplicate numbers into an Access table?

First of all, you can often get the database itself not to accept any duplicate numbers, if you define that table with a unique index over the number. That will work much better than doing it on your side, particularly when the table gets big.

Now to your code.

I left your variable names as they were, so that you will find it easier to compare your code to mine. But in general, all caps for a variable name is rare in Perl. Oh, and contends should probably be contents...
while ($CONTENDS=~/(\d{10})/g) { $match=$1; $IDNUMBER{$match}=1 unless $IDNUMBER{$match}; } foreach $match (keys %IDNUMBER) { $sqlinsert="INSERT INTO $tab[$loop] VALUES('$match')"; $rc=$db->Sql($sqlinsert); die qq(SQL fail "$rc":), $db->Error(),qq(n) if $rc; }

Replies are listed 'Best First'.
Re: Re: How do I avoid inserting duplicate numbers into an Access table?
by CountZero (Bishop) on Mar 06, 2004 at 16:49 UTC
    The reason why you should try to avoid $` and use capturing parentheses in regexes is that it really slows down your regex processing.

    The same goes for and (but to a lesser degree) $&.

    Once you use them anywhere in your script all your regex-processing slows down, even those who do not use these variables.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Re: Re: How do I avoid inserting duplicate numbers into an Access table?
by luoina (Acolyte) on Mar 09, 2004 at 03:26 UTC
    Thank you so much. I am a starter in Perl. What you said help me a lot.....Luoina