in reply to OO design: returning string and/or special value
I'm with 1nickt's comment, in that using context to determine the result for this is somewhat fraught.
Assignment to an array or hash will need scalar context in some cases, which is as much typing as a method argument, and will lead to later programmers wondering what is going on.
my %hash1 = (some_key => $object->method); my %hash2 = (some_key => scalar $object->method);
More generally, though, wantarray works well for returning flat lists or references to lists (although this approach also needs explicit scalar context sometimes).
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: OO design: returning string and/or special value
by wanna_code_perl (Friar) on Oct 07, 2019 at 22:51 UTC | |
by swl (Prior) on Oct 07, 2019 at 23:13 UTC |