Is there a better way to do this? I’m trying to build 2 arrays based on the value of a scalar:
my (@x, @y);
my $r = [$v1, $v2, $v3];
push @x, $r if $s eq 'YES';
push @y, $r if $s ne 'YES';
I tried using:
push $s eq 'YES' ? @x : @y, $r;
with and without parens, but no go.
Error is:
Type of arg 1 to push must be array (not null operation) at comp_report.pl line 79, near "$r;"
push requires its first parameter to be an actual array (at least before perl 5.14 and earlier – it may have changed), not an expression, so you need to:
Beginning in 5.14, builtins such as push experimentally can take arbitrary hard references, so this works: