in reply to elegant array assignment

If I were writing this, I might move the parentheses:

my @arr = ( ref $x eq 'ARRAY' ) ? @$x : ( $x );

That's a pretty irrelevant style consideration, though. I've seen it suggested that ref $x should be compared to ref of a literal. In that case, it'd be like so:

my @arr = ( ref $x eq ref [] ) ? @$x : ( $x );

That's probably a good idea if you can't remember what ref sub {} is (for example), but in this case, I think I'd rather see 'ARRAY' there instead.

(I played around with trying to write something based around eval { @$x } instead of testing ref directly, but it got pretty ugly before it worked: my @arr; eval { @arr = @$x; 1 } || ( @arr = ($x) ))