Is it possible to create an array with conditional items?
my @a = (1, ($condition) ? 2 : \"no-op\", 3);
Such that \"no-op\"
is fu
You can use empty list ()
to skip second element,
my @a = (1, ($condition ? 2 : ()), 3);
Generally speaking, you can get some readability gains using
my @a;
push @a, 1;
push @a, 2 if $condition;
push @a, 3;
In context, that would be
my @rules;
push @rules, $rule->new->name('*.cfg')->prune->discard;
push @rules, $rule->directory->name("_private.d")->prune->discard if $condition;
push @rules, $rule->new->name('*.t')->prune->discard;
push @rules, $rule->new->name('*.bak')->prune->discard;
push @rules, $rule->new->name('.*.bak')->prune->discard;
push @rules, $rule->new->name('.#*')->prune->discard;
my $rule = File::Find::Rule->new()->or(@rules);
my @files = $rule->in(".");