
KevinR
Veteran

Mar 21, 2008, 11:37 AM
Post #13 of 23
(33315 views)
|
Re: [mkeith123] terminate search pattern
[In reply to]
|
Can't Post
|
|
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:
my ($key,$val) = (split ',') [0,1]; <--- an array slice $cid1_rate{$key} = $val; It is similar to writing it like this:
my ($key,$val,undef) = split ','; $cid1_rate{$key} = $val; 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. -------------------------------------------------
|