CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
The best way to get value out of an Excel table?

 



hujirong
Novice

Oct 26, 2010, 7:19 AM

Post #1 of 2 (196 views)
The best way to get value out of an Excel table? Can't Post

Hi

I have tables as shown below. We created them in Excel and save them as tab deliminated text files to be read by Perl at runtime.

DB2C DB2D_DEV DB2D_TST

MF_HOST s1a s12 s1a

MF_PORT 3606 3606 3606

DB2LOAD CSSCI.DB2C.DSNLOAD TSSCI.DB2D.DSNLOAD TSSCI.DB2D.DSNLOAD

DB2EXIT CSSCI.DB2C.DSNEXIT TSSCI.DB2D.DSNEXIT TSSCI.DB2D.DSNEXIT

What's the best way to store them and read them? I can use the following code to store them in a two dimensional array, but to find what I want, e.g. the DB2LOAD of DB2C, I have to search the whole array?

Thanks

Jirong


BillKSmith
Veteran

Oct 26, 2010, 12:59 PM

Post #2 of 2 (193 views)
Re: [hujirong] The best way to get value out of an Excel table? [In reply to] Can't Post

In general, there is no 'best' way.

Your approach works well for small tables. You can search any column or even multiple columns with very little code. For long tables processing speed may be a problem.



If you always want to search the same column, store your data as a hash of arrays. Use the values of your master column as the keys. You can then retrieve the data associated with any key by a single hash reference (ref perldoc perldsc). Searching other columns would be difficult.



If you need the freedom of the first approach and speed is a problem you have to be creative. One possibility is to presort the data file to put the most frequently used column in order. You can then use a binary search on that column.

You can look in CPAN for list or array processing modules to solve special problems.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives