in reply to Re^2: Use of uninitialized value in hash element at
in thread Use of uninitialized value in hash element at

Hi,

thanks for responses... I've tried both solutions and I still get warnings :

Use of uninitialized value in hash element at ....


line with return statement... Is there any chance to get rid of those warnings ?

Thanks in advance, regards, Rob.

Replies are listed 'Best First'.
Re^4: Use of uninitialized value in hash element at
by zwon (Abbot) on Apr 27, 2011 at 17:21 UTC

    Sure. This warning is actually means that $attribute is not defined. You probably calling this method like:

    $self->get_attribute
    somewhere
      Hi,

      thanks for response. I know what is causing this, but I'd just like to return undef if it doesn't exists and value if it exists.

      Why can't I do that without getting this warning ?

      It's not clear to me, why I can't "just ask politely" if it exists and return undef if it doesn't without warning...

      Thanks in advance, regards, Bulek.

        undef is invalid value for hash key, since this warning. If you don't want to see it you can check if $attribute defined or not:

        sub get_attribute { my ( $self, $attribute ) = @_; return defined($attribute) ? $self->{ATTRIBUTES}{$attribute} : und +ef; }