Please tell me what I am doing wrong. i thought h[ErrFieldID] would work
however it doen’t. Thanks. Mom
h = {‘25127’ => ‘RefProvNPI’, ‘10353’ => ‘ProcCode’}
it (“Search for FieldId Tag containing error in XML file”) do
ErrFieldID= get_xml_attrib_value(ie, “Error”,“FieldID”)
puts ErrFieldID #This correctly shows 25127
puts h[ErrFieldID] # should show ‘RefProvNPI’ but doesn’t
end
Mmcolli00 Mom wrote:
 puts ErrFieldID       #This correctly shows 25127
Try p ErrFieldID
Maybe ErrFieldID is not a string or contains spaces or non-printable
characters somewhere.
HTH,
Sebastian
Sebastian H. wrote:
Mmcolli00 Mom wrote:
 puts ErrFieldID       #This correctly shows 25127
Try p ErrFieldID
Maybe ErrFieldID is not a string or contains spaces or non-printable
characters somewhere.
HTH,
Sebastian
No that didn’t work. It only showed the reference key in brackets:
[‘25127’]. I need it to show the value from the hash: ‘RefProvNPI’
Thanks for trying.
Mom
Check the API of whatever gem you are using and check to see if
get_xml_attrib_value returns a single value or an array.
Reuben
On Mon, Aug 4, 2008 at 4:06 PM, Mmcolli00 Mom [email protected]
wrote:
Sebastian H. wrote:
Mmcolli00 Mom wrote:
puts ErrFieldID #This correctly shows 25127
Try p ErrFieldID
No that didn’t work. It only showed the reference key in brackets:
[‘25127’]. I need it to show the value from the hash: ‘RefProvNPI’
It did work. It means that ErrFieldID is an array containing a single
string. Not the same as your hash key, which is just a string.
-Michael
It continues to show the wrong value [‘25127’]. I need it to show the
value from the hash: ‘RefProvNPI’. The ErrFieldID.class returned
‘Array’.
I don’t know what else to try so that it will output the value
‘RefProvNPI’ from the hash. Having a hash will work perfectly for the
program however if I can’t reference the value that the key points to, I
don’t know what else to try. Thanks for helping.
On Mon, Aug 4, 2008 at 4:06 PM, Mmcolli00 Mom [email protected]
wrote:
No that didn’t work. It only showed the reference key in brackets:
[‘25127’]. I need it to show the value from the hash: ‘RefProvNPI’
Try puts ErrFieldID.class to tell you what it really is. Looks like
it is an Array object instead of a string.
Todd
Thanks everyone!
I thought about this being an array and I did this:
StrgErrFieldID = ErrFieldID.to_s
Then I referenced h[StrgErrFieldID]
This worked!
Thanks for all your help and support!
Mom
Hi –
On Tue, 5 Aug 2008, Mmcolli00 Mom wrote:
It continues to show the wrong value [‘25127’]. I need it to show the
value from the hash: ‘RefProvNPI’. The ErrFieldID.class returned
‘Array’.
I don’t know what else to try so that it will output the value
‘RefProvNPI’ from the hash. Having a hash will work perfectly for the
program however if I can’t reference the value that the key points to, I
don’t know what else to try. Thanks for helping.
If it’s an array and you need the first element, how about indexing it
with [0]? Or use the * operator. Also, make sure that you don’t mix
‘25127’ (the string) with 25127 (the integer). As hash keys they are
different from each other.
David
On Tue, Aug 5, 2008 at 8:59 AM, Mmcolli00 Mom [email protected]
wrote:
Thanks everyone!
I thought about this being an array and I did this:
StrgErrFieldID = ErrFieldID.to_s
Then I referenced h[StrgErrFieldID]
This worked!
That will work as long as you can guarantee only one element in the
Array. The fact that the method returns an array and not a single
value indicates to me that there may be times where multiple elements
are a real possibility. You may want to consider accessing the first
element explicitly with ErrFieldID[0] instead of using to_s.
You may also want to consider what to do if you get more than one
element returned in that array.
-Michael
On Tue, Aug 5, 2008 at 6:59 AM, Mmcolli00 Mom [email protected]
wrote:
Thanks everyone!
I thought about this being an array and I did this:
StrgErrFieldID = ErrFieldID.to_s
this would be better:
StrgErrFieldID = ErrFieldID[0]
Since it explicitly says (i) that you’re expecting an array and (ii)
that you’re extracting its first element
martin
Michael
Thanks for the great advice.
Mom Mcolli00