![]() |
| ||
| Beginner question: need help importing tab-delimited file as perl hash Hi everyone, I'm trying to: (1) take an excel spreadsheet with two columns of data (2) convert to tab-delimited text file (3) import into perl as a hash I've managed to import as an array: open (LIST1, "list1.txt") || die "File not found\n"; while (<LIST1>) {push(@list1array, $_)}; close LIST1; However, I can't figure out how to either import directly as a hash or convert the array to a hash. If someone could point me in the right direction, I'd be appreciative. Thanks! |
| ||
| Re: Beginner question: need help importing tab-delimited file as perl hash Quote:
I would do it something like this: open (LIST1, "list1.txt") || die "File not found\n"; Which will open the file, read in the data line by line, split the current line by the tab character (so that what is in the first column will be in tmpvar1, and what is in the second column will be in tmpvar2) then assign the hash in a scalar context. I've tested it with a tab delimited text file, and it works fine for me.... let me know how it works for you. |
| ||
| Re: Beginner question: need help importing tab-delimited file as perl hash Works great. Thanks for the assistance! |
| All times are GMT -4. The time now is 6:24 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC