in reply to sub returns array or empty array
Somewhat related to the comment by Fletch above, you could use an ARRAYref on success (which would be empty for no results), and a scalar containing an error message on failure.
sub requestDB { ... if ($some_error) { return "This error occurred: $DBI::errstr"; } return \@results; # reference to results array } my $a = requestDB(...); if ( ! ref $a ) { # if $a is not a reference, it's a scalar that holds the error mes +sage die $a; } elsif (@$a) { # if @$a is nonzero, there were results ... } else { # there weren't results print "No results found, sorry!" }
|
|---|