in reply to elegant array assignment

The eval method (or the isArray() I've told tye to submit somewhere on CPAN) is the best way to find out if something responds to @{}.

In general, I find that code like that is attempting to compensate for "clever" code elsewhere. And, by "clever", I mean "poorly written". I'm betting that whatever populates $x does something like:

sub some_function { # Stuff here that populates @x return @x > 1 ? \@x : $x[0]; }
That meme is one of the most horrendous ones to work with.
  1. some_function() will almost always return a single thing.
  2. We know this because some_function() expects that the assignment is always to a scalar, otherwise why normalize to a scalar?
  3. But, since some_function() builds an array, it might return more than one thing.
  4. So, the caller has to know this and normalize back to an array.

So, given that the proper normalization (as performed by sane callers) is to an array, why is some_function() normalizing to a scalar? Simply put, there's no good reason to, other than FUD. Remove the FUD, trust the array, and stop the silliness.


My criteria for good software:
  1. Does it work?
  2. Can someone else come in, make a change, and be reasonably certain no bugs were introduced?