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

sub get_attribute { my ( $self, $attribute ) = @_; return exists $self->{ATTRIBUTES} ? $self->{ATTRIBUTES}{$attribute} : undef; }
will do the same, but if you don't mind to create $self->{ATTRIBUTES}, it maybe even shorter:
sub get_attribute { my ( $self, $attribute ) = @_; return $self->{ATTRIBUTES}{$attribute}; }

Replies are listed 'Best First'.
Re^3: Use of uninitialized value in hash element at
by Anonymous Monk on Apr 27, 2011 at 17:12 UTC
    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.

      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.