in reply to Spotting an empty array as argument
Perl "flattens" arrays and hashes passed as parameters to a sub into a list of scalar values (see the perlsub Description section, paragraph two. In your case it is not possible for the sub to tell the difference between a call with no parameters and a call containing one or more empty array and empty hash parameters.
Perhaps a solution is to use a "sayArray" sub that does the multi-line thing and use Perl's "say" in other cases? That has the advantage that it clearly signals to the user that something special is happening in the array case.
Perl's built in "say" doesn't need any magic for handling a "no argument" case. It just does what print does (in that case it prints nothing) then prints a newline, which is what it always does.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Spotting an empty array as argument
by Chuma (Scribe) on Mar 25, 2021 at 21:01 UTC | |
by choroba (Cardinal) on Mar 25, 2021 at 21:39 UTC | |
by ikegami (Patriarch) on Mar 26, 2021 at 19:32 UTC | |
by LanX (Saint) on Mar 26, 2021 at 20:36 UTC | |
by ikegami (Patriarch) on Mar 27, 2021 at 05:56 UTC | |
by LanX (Saint) on Mar 26, 2021 at 10:46 UTC |