return sort 

sub all_authors {
    my %authors;
    foreach my $book (@_) {
        $authors{$_}++ foreach $book->authors;
    }
    return wantarray ? sort keys %authors : keys %authors;
}

say "Total unique authors: " . all_authors(@books);
Total unique authors: 4