firewallcj
firewallcj

Reputation: 51

Use of uninitialized value $Row[3] in concatenation (.) or string

Im currently get this error on my OTRS system and i cant figure out what is happening.

Error on syslog:

There was an error executing Execute() in Kernel::System::Console::Command::Maint::Survey::RequestsDelete: Use of uninitialized value $Row[3] in concatenation (.) or string at /opt/otrs/Kernel/System/Console/Command/Maint/Survey/RequestsDelete.pm line 132.

Part of code which faulty:

# fetch the result        
while ( my @Row = $DBObject->FetchrowArray() ) {

                my $Result = join(
                    ' ', "Survey:" . $Row[0] . "\t",
                    "TicketNumber:" . $Row[1] . "\t",
                    "SendTime:" . $Row[2] . "\t",
                    "VoteTime:" . $Row[3] . "\t",
                    "CreateTime:" . $Row[4] . "\t"
                );

                $Self->Print("$Result\n");
            }

Upvotes: 0

Views: 936

Answers (1)

lthemick
lthemick

Reputation: 318

Can you verify the db schema for the table accessed via $DBObject->FetchrowArray()? First thing is to ensure those fields actually exist.

Whether you can validate the schema or not, it's good practice to perform validation against the fields and provide a default value if not e.g.

$Row[3] = '' if not defined $Row[3];

or

$Row[3] = '-' if not defined $Row[3];

or

$Row[3] = 'not defined' if not defined $Row[3];

or

$Row[3] //= 'not defined';

Then your code is protected against missing data.

Just use a default value that makes sense for the output.

Upvotes: 4

Related Questions