我在数据库中存储了以下php序列化数组。我正在尝试用perl反序列化数据并且遇到问题。请参阅下面的代码。
my $x=`a:40 {i:0;s:7:"4103155";s:9:"commentid";s:7:"4103155";i:1;s:1:"0";s:8:"parentid";s:1:"0";i:2;s:1:"0";s:5:"refno";s:1:"0";i:3;s:10:"1502910309";s:10:"createdate";s:10:"1502910309";i:4;s:13:"72.38.116.178";s:8:"remoteip";s:13:"72.38.116.178";i:5;s:6:"aac0a2";s:11:"fingerprint";s:6:"aac0a2";i:6;s:4:"3685";s:5:"locid";s:4:"3685";i:7;s:1:"0";s:6:"clubid";s:1:"0";i:8;s:1:"0";s:9:"profileid";s:1:"0";i:9;s:1:"0";s:6:"userid";s:1:"0";i:10;s:1:"0";s:6:"global";s:1:"0";i:11;s:1:"0";s:8:"official";s:1:"0";i:12;s:1:"1";s:10:"legacyuser";s:1:"1";i:13;s:1:"0";s:7:"mediaid";N;i:14;s:1:"1";s:6:"status";s:1:"1";i:15;s:25:"comment string";s:7:"comment";s:25:"comment string";i:16;s:1:"0";s:5:"likes";s:1:"0";i:17;s:1:"0";s:8:"dislikes";s:1:"0";i:18;s:1:"0";s:6:"import";s:1:"0";i:19;s:4:"theauthorname";s:6:"author";s:4:"theauthorname";}`;
my %hash; my ($key,$value);
my @tokens = $x =~ m/"(.*?)"/g;
$hash{$key}= $value while (($key, $value)= splice(@tokens,0,2));
print Dumper(\%hash);
结果如下:
$VAR1 = {
'72.38.116.178' => 'aac0a2',
'4103155' => '0',
'status' => '1',
'parentid' => '0',
'userid' => '0',
'official' => '0',
';i:18;s:1:' => ';s:6:',
';i:16;s:1:' => ';s:5:',
'0' => '0',
'createdate' => '1502910309',
';s:6:' => ';s:4:',
'mediaid' => '1',
';s:7:' => ';s:25:',
';s:8:' => ';s:1:',
'1' => '0',
';s:1:' => ';i:19;s:4:',
'clubid' => '0',
'3685' => '0',
'fingerprint' => 'aac0a2'
};
这不正确(输出)。 我对perl非常陌生。
有人可以协助修复此代码,以便正确提取php序列化字符串吗?