Jump to content
Sign in to follow this  

2D array or database?

Recommended Posts


I was asking questions for reading .csv file into a 2D array. However, I am was also wondering if database processing is more suitable in my case.

Let's say I want to write a test app, and all test input variables are stored on a data file (not in the script). If I want to add more stuff to test, I can simply add/remove data to the existing file, without modifying the dramatically. For example,

Title|Name|Pay|Employee|Holiday|Company phone



Outside Vendor|Apple Inc||||4088006000




If i have I want to test more, I can simply add a line to the data file:

Engineer|New|30000|Yes|0 or

Outside Vendor|IBM Inc||||8003001234

My goal is, I want to easily read my test variable from array[Don][Pay], and compare with array[Tina][Pay]. The current challenge I am facing:

1. If it's an array, I cannot read the variable as array[Don][Pay], but array[6][2], which is not very intuitive.

2. The index of the array will be changed when new data add in, for example, array[6][2] may change to array[7][2] if I update the test input file later.

Any suggestion?

Share this post

Link to post
Share on other sites

IMO, the best way to do this is to keep your data always in a file (csv, spreadsheet or whatever else) - you can add new lines to that file, remove lines ...

When your script will be processing data from that file, the best way to do it will be to open the file, read all the file in one array, close the file and do all the processing using the array you have in memory, after all is done, you can write the new array to the file.

This way has a couple advantages: you are working with data which is in memory so the processing speed will be better (reading values from the file sequentially is slower) and the 2nd advantage: you won't keep the file open for long time (maybe someone else need to edit that file).

SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post

Link to post
Share on other sites

@sfresher...Why not just use a database? Look up SQLite in the helpfile.


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this