Is there a way to assing a value to the hash elements before they get assigned an elements so they are not 'undef'. I tried an if (!defined) thing but it was thowing errors.
Don't do that. Almost always undef warnings point to a logic error. If you mask the warning you are ignoring the logic error. Better to figure out how you get into the state where the warnings are generated then fix the root cause than to paper over the cracks until the whole thing falls down around your ears.