Improve detection of installed packages

The previous mechanism failed when the package name
got truncated by "dpkg-query -l", for instance:

  $ dpkg-query -l libreadline-dev
  Desired=Unknown/Install/Remove/Purge/Hold
  | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
  |/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
  ||/ Name           Version      Architecture Description
  +++-==============-============-============-=================================
  ii  libreadline-de 6.2-9        amd64        GNU readline and history librarie

where libreadline-de is not the same as libreadline-dev (!)