C
ccc31807
This is embarrassing!
I read an input file, split each row on the separators, pick out the
unique key (which consists of seven digits), create a hash element on
the key, and read the other values into an anonymous hash. This has
worked for years without a hitch.
Yesterday, my user requested the app to print a calculated field,
which is a list of names contained in a secondary file. I thought, "No
problem, I'll just create a new element in my anonymous hash,
concatenate each name unless the name already matched the string, and
print it out." Didn't work, but the errors seemed to be random and
arbitrary.
After a couple of hours, I used bdf's trick to print out the hash, and
discovered much to my embarrassment that the keys weren't the same. In
the main loop where I created the hash, the keys were as expected and
consisted of seven characters which are all digits. HOWEVER, in the
loop where I created the additional hash element, the keys with
leading zeros did not match. Here is an example of the hash:
0123456 => HASH(deadbeed)
id => 0123456
name => joe
gender => male
new_field =>
123456 => HASH(deadbeef)
new_field => list of concatenated strings
I read the main file and create the main hash on the unique key, one
element of which is 'new_field' with an initial value of ' '. Then, I
read a secondary file which contains the key and ATTEMPT to
concatenate an element to the main hash element new_field. Instead, it
creates a new hash element with the numeric value of the unique key
instead of the string value.
So, I guess my question is how I convert an integer to a string to
preserve the leading zeros.
According to MJD on his infrequently asked questions page, the answer
is, "Try using a whip." But that doesn't tell me what kind of whip.
http://perl.plover.com/IAQ/IAQlist.html#how_can_i_force_perl_to_treat_a_number_as_a_string
CC.
I read an input file, split each row on the separators, pick out the
unique key (which consists of seven digits), create a hash element on
the key, and read the other values into an anonymous hash. This has
worked for years without a hitch.
Yesterday, my user requested the app to print a calculated field,
which is a list of names contained in a secondary file. I thought, "No
problem, I'll just create a new element in my anonymous hash,
concatenate each name unless the name already matched the string, and
print it out." Didn't work, but the errors seemed to be random and
arbitrary.
After a couple of hours, I used bdf's trick to print out the hash, and
discovered much to my embarrassment that the keys weren't the same. In
the main loop where I created the hash, the keys were as expected and
consisted of seven characters which are all digits. HOWEVER, in the
loop where I created the additional hash element, the keys with
leading zeros did not match. Here is an example of the hash:
0123456 => HASH(deadbeed)
id => 0123456
name => joe
gender => male
new_field =>
123456 => HASH(deadbeef)
new_field => list of concatenated strings
I read the main file and create the main hash on the unique key, one
element of which is 'new_field' with an initial value of ' '. Then, I
read a secondary file which contains the key and ATTEMPT to
concatenate an element to the main hash element new_field. Instead, it
creates a new hash element with the numeric value of the unique key
instead of the string value.
So, I guess my question is how I convert an integer to a string to
preserve the leading zeros.
According to MJD on his infrequently asked questions page, the answer
is, "Try using a whip." But that doesn't tell me what kind of whip.
http://perl.plover.com/IAQ/IAQlist.html#how_can_i_force_perl_to_treat_a_number_as_a_string
CC.