我有从一个数据库中提取序列化综合网址数据、将其进行航空、对数据进行模拟、然后重新编号的每字母。 我想做的是修改名称和插图;地毯(如下文所示),但可以说明如何进入各个田地加以修改:
use PHP::Serialization qw(serialize unserialize);
use Data::Dumper qw(Dumper);
###blah, blah, blah
while ( @a = $sth->fetchrow() ){
my $hashref = unserialize( $a[0] );
print Dumper($hashref);
}
OUTPUT:
$VAR1 = [
bless( {
name => Fred , # I want this to be Dave
pet => Cat , # I want this to be Dog
date => 1977
}, PHP::Serialization::Object::stdClass ),
bless( {
name => Mary , # I want this to be Jane
pet => Worm , # I want this to be Pig
date => 1977
}, PHP::Serialization::Object::stdClass )
];
UPDATE: Thx to Hugmeir, I have the following, which seems to work. Is this the best way to change the name if I don t know the index number?
for my $hashref (@{$array_ref}) {
if ( $hashref->{name} =~ /Mary/ ){
$hashref->{name} = Jane ;
}
}