Programmer Question
Possible ways:
Using push:
my @list;
push @list, 'foo' if $foo;
push @list, 'bar' if $bar;Using the conditional operator:
my @list = (
$foo ? 'foo' : (),
$bar ? 'bar' : (),
);Using the
x!!
Boolean list squash operator:my @list = (
('foo') x!! $foo,
('bar') x!! $bar,
);
Which one is better and why?
No comments:
Post a Comment