in reply to Count elements in array ref

Why don't you just check whether data() returned something?

Alternatively, have data() return an empty arrayref when there is nothing to return.