On Thu, 2006-02-02 at 16:52 -0800, Sanjay Chandriani wrote: > Hi, > > Ok, so I see my question was unclearly posed. Here's what I want to do: > > I have two tab-delimited text files. > > File one: > column 1: UNIQUE identifiers (about 40,000), one identifier per line. > column 2: some description of the identifier (let's say, red, green or > blue). > > For example, the 9th identifier down might be 'hat' and it's > description in the next column over is 'blue'. > > File two: > column 1: a subset of the identifiers found in file one, column 1 > (about 1,000) > > This is what I would like to do: > > Make a second column in file 2 with the correct description to the > identifier as described in the master file (file 1). > > So, in the end, my second file should have the following TWO columns: > column 1: a subset of the identifiers found in file one, column 1 > (about 1,000) > colum 2: the appropriate description (red, green or blue) as > instructed by file 1. > > vlookup in excel can do this for me, but it is very slow. So, if i > had a perl script that can let me achieve my goal, i am sure it will > be faster. Any help would be greatly appreciated.
Hey Sanjay, A vlookup is a poor person's hash. First you need to get hold of your data somehow, eg reading it in from a csv file or something. my %vlookup; $vlookup{'foo'} = "bar"; $vlookup{'item1'} = 1.25; $vlookup{'code'} = 'abcde'; # now we have a hash structure filled with values you can get at by key # so $vlookup{'foo'} will return the value associated with foo, ie 'bar' in this case print "\$vlookup{'foo'} is ", $vlookup{'foo'}, "\n"; it gets more complex than this when you want to keep a bunch of things associated with a unique id. eg using only the id you can get say the price, the qty remaining, the original manufacturer, a short description why we won't sell this to customer A under any circumstances etc. bash$ perldoc perldsc has more of the details you require. Other things to do is search CPAN for Spreadsheet modules to read and write in .xls format if you require this, or alternatively research how to reliably read csv files, which isn't quite as easy as it might first appear - however with that caveat I'm sure you'll find a recipe :) HTH Hal -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>