我想做与下面相同的事情
my @nucleotides = ('A', 'C', 'G', 'T');
foreach (@nucleotides) {
print $_;
}
但使用
use constant NUCLEOTIDES => ['A', 'C', 'G', 'T'];
我怎样才能做到这一点 ?
最佳答案
use constant NUCLEOTIDES => [ qw{ A C G T } ];
foreach (@{+NUCLEOTIDES}) {
print;
}
但要注意:虽然 NUCLEOTIDES 是一个常量,但引用数组的元素(例如
NUCLEOTIDES->[0]
)仍然可以修改。
关于arrays - 如何遍历 perl 常量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8972457/