Generate list with conditional items

后端 未结 2 514
臣服心动
臣服心动 2021-01-22 06:40

Is it possible to create an array with conditional items?

my @a = (1, ($condition) ? 2 : \"no-op\", 3);

Such that \"no-op\" is fu

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-22 07:10

    You can use empty list () to skip second element,

    my @a = (1, ($condition ? 2 : ()), 3);
    

提交回复
热议问题