\n my $invoices = $dbh->selectall_arrayref("\n SELECT\n *\n FROM\n cl_orders\n WHERE\n cl_orders.cid=?",\n { Slice => {} }, $sid) || die $dbh->errstr;\n\n unless ($sid < 0 and $sid > -8 and $args{key} == 1) {\n # -1 to -7 = test schools, so won't appear in cl_orders etc\n return undef unless grep { $_ == $args{key} } map { ($_->{registration_num}) } @$invoices;\n }\n
That has to be some of the worst code I have ever seen. "registration_num" isn't even a number, it's alphanumeric.
here's my version:
\n my $invoices = $dbh->selectrow_array(" SELECT 1\n FROM cl_orders\n WHERE cid = ?\n AND registration_num = ?",\n {}, $sid, $args{key});\n\n # -1 to -8 = test schools, so won't appear in cl_orders etc\n return undef unless($invoices || (($sid < 0) and ($sid > -8))); \n
I hope that's a little more clear.