perlhashotrs

Reference found where even-sized list expected - OTRS issue


I'm get this error on my OTRS system, and I can't figure out what is happening.

Error on syslog:

There was an error executing Execute() in Kernel::System::Console::Command::Maint::Ticket::PendingCheck: Reference found where even-sized list expected at /opt/otrs/Kernel/System/GenericAgent.pm line 988.

Part of code which is faulty:

# add note if wanted
if ( $Param{Config}->{New}->{Note}->{Body} || $Param{Config}->{New}->{NoteBody} ) {
    if ( $Self->{NoticeSTDOUT} ) {
        print "  - Add note to Ticket $Ticket\n";
    }

    my %Ticket = $TicketObject->TicketGet(
        TicketID      => $Param{TicketID},
        DynamicFields => 0,
    );

    if ( IsHashRefWithData( \%Ticket ) ) {

        my %CustomerUserData = {}; # heres the line 988
        if ( IsStringWithData( $Ticket{CustomerUserID} ) ) {
            %CustomerUserData = $Kernel::OM->Get('Kernel::System::CustomerUser')->CustomerUserDataGet(
                User => $Ticket{CustomerUserID},
            );
        }

Solution

  • The message you see is a warning, not an error. If you add use diagnostics;, you will get more details about the issue:

    (W misc) You gave a single reference where Perl was expecting a list
    with an even number of elements (for assignment to a hash).  This
    usually means that you used the anon hash constructor when you meant
    to use parens.  In any case, a hash requires key/value pairs.
    
        %hash = { one => 1, two => 2, };    # WRONG
        %hash = [ qw/ an anon array / ];    # WRONG
        %hash = ( one => 1, two => 2, );    # right
        %hash = qw( one 1 two 2 );                  # also fine
    

    To avoid the warning, you can change:

    my %CustomerUserData = {}; # heres the line 988
    

    to:

    my %CustomerUserData;