in reply to Use of uninitialized value in hash element at

sub get_attribute { my ( $self, $attribute ) = @_; return exists $self->{ATTRIBUTES} && exists $self->{ATTRIBUTES}{$a +ttribute} ? $self->{ATTRIBUTES}{$attribute} : undef; }

Replies are listed 'Best First'.
Re^2: Use of uninitialized value in hash element at
by zwon (Abbot) on Apr 06, 2011 at 12:50 UTC
    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}; }
      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