I'm running the following function against a PostgreSQL database and a few tables to come up with a list of addresses that should be notified about messages that match a certain criteria. The most obvious thing for me to do was create a SQL SELECT statement which given some parameters would just return the right values. The issue I ran into is that I need to use the $message -> {'userid'} value more than once. The existing usage I've detailed looks wrong to me and I'm wondering if any of you have suggestions for either easing my mind or better ideas.
sub notify_users { my $message = shift; # Get the list of addresses to notify my @addr = @{$dbh -> selectall_arrayref(q[ SELECT addr FROM email, (SELECT userid FROM usernames WHERE 0 <> position(lower(username) IN ?) AND userid <> ? EXCEPT SELECT userid FROM ignore WHERE ignore_userid = ?) ids WHERE email.userid = ids.userid], undef, lc $message -> {'message'}, $message -> {'userid'}, $message -> {'userid'})}; # flatten the array $_ = $_ -> [0] for @addr; @addr = grep length(), @addr; return unless @addr; .... }
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |