这是我使用Moose创建的一个类,我想做以下操作:更新2D数组Stack_dG的每个元素,如果且仅当对象通过子例程'_scale_energy_parameters'使用默认的37以外的温度构建。
现在,我知道我可以用$self->Stack_dG->[$i][$j]
访问Stack_dG中的值。但是我如何更新这个值(需要设置另一个值)?
我已经显示了一部分代码,但我有很多对*_dG和*_dH属性,我想通过'_scale_energy_parameters'方法更新每个*_dG。有没有办法在不为每个句柄创建不同句柄的情况下做到这一点?
提前感谢!附:这是我与Moose合作的第一个项目,我愿意听取你的任何建议!LP
#############################
# Energy.pm
#############################
{
package Energy;
use Moose;
use Moose::Util::TypeConstraints;
use Moose::Meta::Attribute::Native::Trait::Array;
# Constant to convert °C<=>°K
has k0 => (is => 'ro', isa => 'Num', default => 273.15);
# PUBLIC double Tmeasure = 37+K0; /* temperature of param measurements */
has Temperature => (is => 'ro', isa => 'Int', default => 37, trigger => &_scale_enery_parameters);
sub _scale_enery_parameters
{
my $self = shift;
for(my $i=0;$i<8;$i++)
{
for(my$j=0;$j<8;$j++)
{
$self->update_Stack(8*$i+$j, ($self->Stack_dH->[$i][$j] - ($self->Stack_dH->[$i][$j] - $self->Stack_dG->[$i][$j]) * ($self->Temperature()+$self->k0()) ));
}
}
}
# Stack_d*->[NBPAIRS+1][NBPAIRS+1]
has Stack_dG => (
is => 'rw',
isa => 'ArrayRef[ArrayRef[Int]]',
handles => { update_Stack => 'set'},
default => sub {
[
[ 1e7, 1e7, 1e7, 1e7, 1e7, 1e7, 1e7, 1e7 ],
[ 1e7, -240, -330, -210, -140, -210, -210, -140 ],
[ 1e7, -330, -340, -250, -150, -220, -240, -150 ],
[ 1e7, -210, -250, 130, -50, -140, -130, 130 ],
[ 1e7, -140, -150, -50, 30, -60, -100, 30 ],
[ 1e7, -210, -220, -140, -60, -110, -90, -60 ],
[ 1e7, -210, -240, -130, -100, -90, -130, -90 ],
[ 1e7, -140, -150, 130, 30, -60, -90, 130 ]
]
}
);
has Stack_dH => (
is => 'rw',
isa => 'ArrayRef[ArrayRef[Int]]',
default => sub {
[
[ 1e7, 1e7, 1e7, 1e7, 1e7, 1e7, 1e7, 1e7],
[ 1e7, -1060, -1340, -1210, -560, -1050, -1040, -560],
[ 1e7, -1340, -1490, -1260, -830, -1140, -1240, -830],
[ 1e7, -1210, -1260, -1460, -1350, -880, -1280, -880],
[ 1e7, -560, -830, -1350, -930, -320, -700, -320],
[ 1e7, -1050, -1140, -880, -320, -940, -680, -320],
[ 1e7, -1040, -1240, -1280, -700, -680, -770, -680],
[ 1e7, -560, -830, -880, -320, -320, -680, -320]
]
}
);
__PACKAGE__->meta->make_immutable;
no Moose; # turn off Moose-specific scaffolding
1;
}
您应该能够简单地分配给它:
$self->Stack_dG->[$i][$j] = 42;
还是我误解了问题?