obtaining the distance between two objects

Hi!

I am a total newbie to scripting but I have a problem which I believe could be solved using some basic code. Basically I need to obtain the distance from an object and use it inside a cycles shader.

Could someone give me some help with this?

Thanks a lot!