Searching an array

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
DWEd
Newbie
Posts: 12
Joined: Fri Jul 15, 2016 2:54 pm

Searching an array

Post by DWEd » Thu Feb 09, 2017 5:00 pm

Hi, is there a quicker way of searching an array.
I'm currently reading in a lookup file and then running line by line through a much larger text file and then acting on that line if it's found in the lookup file.

The lookup file is 115 lines long, has a lookup and replacement value separated by a comma and is loaded into an array called "Replacement". I then read in a variable "outputstring" from a line in the larger file and run a loop that's basically

Code: Select all

 
repeat>findcolour
    Let>tmp=Replacement_%findcolour%
    Separate>tmp,COMMA,replacebits
       if>outputstring=replacebits_1
         let>namecolour=replacebits_2
         let>foundcolour=yes
         let>findcolour=999
       else
         let>findcolour=findcolour+1
       endif
     Until>findcolour>%Replacement_COUNT%
This works fine, but as the larger file is thousands of lines long this lookup does seem to slow things down a bit. Is there a way I can search an array more efficiently without looping through it?

User avatar
JRL
Automation Wizard
Posts: 3530
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Searching an array

Post by JRL » Thu Feb 09, 2017 10:10 pm

Have you ever used SQL to search a database? You can also use SQL to search a comma delimited file. Much faster than reading line by line. I've used it to search through millions of lines in a few seconds.

As a starting point, see Marcus' blog
https://www.mjtnet.com/blog/2009/10/05/ ... csv-files/

DWEd
Newbie
Posts: 12
Joined: Fri Jul 15, 2016 2:54 pm

Re: Searching an array

Post by DWEd » Fri Feb 10, 2017 10:03 am

I've not really used SQL before, but I can't see it being too much of a challenge for such a simple search.
Thanks for the link, I'll have a look into it.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts