Challenge 2: A Context-Aware Subroutine — Possible Solution ==================================================================== use strict; use warnings; use feature 'say'; sub get_names { my @names = ("Ada", "Grace", "Alan"); if (wantarray()) { return @names; } else { return scalar(@names) . " names"; } } my @all = get_names(); my $count = get_names(); say "@all"; say $count; Output: Ada Grace Alan 3 names WHY THIS WORKS AS AN ANSWER ------------------------------ This reuses the chapter's own get_data-style wantarray pattern directly, generalized from Course 1, Chapter 7's original get_scores example — wantarray() checks how get_names was actually called, letting the same subroutine body produce two genuinely different results depending on the caller. my @all = get_names(); assigns to an array, putting the call in LIST context (Course 1, Chapter 3's own context rules, applying identically to subroutine calls). wantarray() returns true, so return @names; hands back all three names, which @all receives in full. my $count = get_names(); assigns to a scalar instead, putting the exact same call in SCALAR context. wantarray() now returns false, so the else branch runs: scalar(@names) forces the array into scalar context explicitly (reusing this chapter's own scalar(...) forcing-context tool) to get the count, 3, and . " names" (Course 1, Chapter 2's concatenation operator) appends the literal text, so the final returned value is the STRING "3 names" — not just the bare number 3, exactly what the challenge specifically asks for rather than the plain count Course 1's own example returned.