The posted code shows that perl it self somehow were able to tell the differense...
It doesn't. Apart from the value of $mode, these two lines do the same thing.
return 42 if $mode eq 'a'; return (42) if $mode eq 'b';
The parentheses are superfluous; they do not change the behavior in this case.
In the final case:
my @l = (42); return @l if $mode eq 'c';
The return value depends on the context in which the caller of this function invoked it. When a function called in scalar context (as you've shown here) returns an array, that return value evaluates to the number of elements in the array.
Oh, and the parentheses in the assignment to the array are also superfluous. This code is equivalent:
my @l = 42;If you'd like to learn more about context, the first chapter of Modern Perl explains it in detail.
In reply to Re^3: Detecting type of output from subs
by chromatic
in thread Detecting type of output from subs
by mogul
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |