The perl code you have written is completely wrong unless you are using a version of perl I am totally unfamiliar with.

To read a file you must open it:

Code

open (IN, 'mv_0000001.txt') or die "$!"; while(<IN>){ here you read/parse the lines of the file } close IN

You must be in the directory the file is in or the file must be in the same folder as the script to open and read it with just using the filename. Or just use the full path to the file, if you know it, in the open() function. This line is just wrong for many reasons:

Code

my %cid1_rate = {/ls=a\w ls=a\w qw//[],/n qw//[],/n};

It is not going to do anything except throw an error. Your explanation makes no sense, maybe because the image is too blurry to read. Post the real lines of whatever it is you are trying to parse and it might make sense. -------------------------------------------------

That will not print the key/value pair in the same order they were in the file because hashes have no guaranteed order. That could be fixed though by using an array. -------------------------------------------------

It works! The only thing is, there are only about half the key value pairs printing out. I found one of the key value pairs, and it is correct, but still I could not find many others. It seems what is there is correct, just not complete.

Mike

Mike, it is correct for the sample data you posted:

1: 124578,2,2003-03-04 26673,4,2005-12-11

Thats all I can go by. If the real data is different you have to adjust the code. -------------------------------------------------

If Notepad does not display the file correctly it was maybe written on a different operating system than the one you use to view it with or was written using a word processor and uses line endings Notepad does not recognize (as well as other data Notepad may not understand).

For the sample lines you posted my code splits on the comma but only returns the first two fields: [0,1] and assigns them to $key and $val respectively:

where the third field returned from the split function is undefined (undef) essentially deleting it right after creating it.

If the "key" is repeated in the file, for example:

124578,2,2003-03-04 #2nd line

if 124578 is repeated again the previous key/value pair is overwritten with the new key/value pair because hash keys are unique, there can never be two identical hash keys in the same hash. If you have a hash key that can have more than one value you would use a different data structure: a hash of arrays probably. But they might be getting too far ahead in your perl education. The code you posted previoulsy is so entirely wrong in concept (and syntax) that I think you may have skipped too much of the basic perl concepts, you might want to review your progress.

That is just a suggestion based only on what I can see, as far as I know you are another Einstein and could learn perl in a couple of days if you wanted to. It took me a few years to get to what I would call competent with perl, but I am also largely self taught and was in no hurry to learn perl, I picked it up as I went along on a need-to-know basis and have large gaps in my perl knowledge still left to be filled in. -------------------------------------------------

Well now you know why my perl is so ugly, but at least 'i am trying. I was trying to do everthing in one line, which obviously doesn't work. I needed to declare the hash etc.

OK, so when the split sees the first comma, it assigns the number to the left as the key, and the number to the right as its value? What about the second comma in each line?

Mike

I give you plenty of credit for trying. To me that says a lot. I much prefer to help people that are trying and seem interested in learning and not in just getting answers.

As far as split() goes. The way I wrote it, using an array slice, Perl only returns the first two fields created by splitting on the pattern (the comma in this case). The second comma and the rest of the line is just ignored. If you want all the fields (or columns as they are often called) returned you would split to an array or a list that has scalars for all the fields. -------------------------------------------------

Mine comes up in a seperate commmand prompt window, then at the end it says press any key to continue. When I do that the window closes. I am running vista on my laptop. There are about 250 pairs. Must be something on my end. I try running it on my pc with xp.

I read the part where you said you got about 250 keys, the rest of your post I didn't read. Now I scanned through it and it is not something I am interested in helping with. -------------------------------------------------

If there really is a million dollar prize, you should hire a really good programmer to help you. I'm not that person. I am a self taught perl coder, I would not make any claims to being a programmer. If you ever want to send me a donation, for whatever reason, send me a PM and I will let you know how. -------------------------------------------------