我有一个数组散列的散列。哈希的键是$duration
和$attr
。我想降序排序$b <=> $a
并仅删除那些具有相同持续时间的重复值。在片段中,这些应该是流:
'h264/AVC, 1080p24 /1.001 (16:9)' & 'AC3, English, multi-channel, 48kHz'
具有持续时间'26'
但不是具有 $duration '2124'
&的重复值'115'
。
删除重复项的示例不计其数,我已经尝试了所有可以找到的方法来满足我的需要,但没有成功。我的解决方案应该是什么方法。谢谢。
my ( %recordings_by_dur_attr ) = ();
push( @{ $recordings_by_dur_attr{ $duration }{ $attr } }, @stream );
print Data::Dumper->Dump( [\%recordings_by_dur_attr] );
结果:
$VAR1 = {
'2124' => {
'00300.mpls, 00-35-24' => [
'',
'h264/AVC, 480i60 /1.001 (16:9)',
'AC3, English, stereo, 48kHz'
]
},
'50' => {
00021.mpls, 00-00-50' => [
'',
'h264/AVC, 1080p24 /1.001 (16:9)',
'AC3, English, multi-channel, 48kHz'
]
},
'6528' => {
'00800.mpls, 01-48-48' => [
'',
'Chapters, 18 chapters',
'h264/AVC, 1080p24 /1.001 (16:9)',
'DTS, Japanese, stereo, 48kHz',
'DTS Master Audio, English, stereo, 48kHz',
'DTS, French, stereo, 48kHz',
'DTS, Italian, stereo, 48kHz',
'DTS, German, stereo, 48kHz',
'DTS, Spanish, stereo, 48kHz',
'DTS, Portuguese, stereo, 48kHz',
'DTS, Spanish, stereo, 48kHz',
'DTS, Russian, stereo, 48kHz'
]
},
'26' => {
'01103.mpls, 00-00-26' => [
'',
'h264/AVC, 1080p24 /1.001 (16:9)',
'AC3, English, multi-channel, 48kHz'
],
'01102.mpls, 00-00-26' => [
'',
'h264/AVC, 1080p24 /1.001 (16:9)',
'AC3, English, multi-channel, 48kHz'
],
'00011.mpls, 00-00-26' => [
'',
'h264/AVC, 1080p24 /1.001 (16:9)',
'AC3, English, multi-channel, 48kHz'
]
},
'115' => {
'00304.mpls, 00-01-55' => [
'',
'h264/AVC, 480i60 /1.001 (16:9)',
'AC3, English, stereo, 48kHz'
]
}
};
重复结构
'',
'h264/AVC, 1080p24 /1.001 (16:9)',
'AC3, English, multi-channel, 48kHz'
删除重复结构的想要结果:
$VAR1 = {
'2124' => {
'00300.mpls, 00-35-24' => [
'',
'h264/AVC, 480i60 /1.001 (16:9)',
'AC3, English, stereo, 48kHz'
]
},
'50' => {
00021.mpls, 00-00-50' => [
'',
'h264/AVC, 1080p24 /1.001 (16:9)',
'AC3, English, multi-channel, 48kHz'
]
},
'6528' => {
'00800.mpls, 01-48-48' => [
'',
'Chapters, 18 chapters',
'h264/AVC, 1080p24 /1.001 (16:9)',
'DTS, Japanese, stereo, 48kHz',
'DTS Master Audio, English, stereo, 48kHz',
'DTS, French, stereo, 48kHz',
'DTS, Italian, stereo, 48kHz',
'DTS, German, stereo, 48kHz',
'DTS, Spanish, stereo, 48kHz',
'DTS, Portuguese, stereo, 48kHz',
'DTS, Spanish, stereo, 48kHz',
'DTS, Russian, stereo, 48kHz'
]
},
'26' => {
'00011.mpls, 00-00-26' => [
'',
'h264/AVC, 1080p24 /1.001 (16:9)',
'AC3, English, multi-channel, 48kHz'
]
},
'115' => {
'00304.mpls, 00-01-55' => [
'',
'h264/AVC, 480i60 /1.001 (16:9)',
'AC3, English, stereo, 48kHz'
]
}
};
后期处理
for my $duration ( sort { $b <=> $a } keys %recordings_by_dur_attr ) {
for my $attr ( keys $recordings_by_dur_attr{ $duration } ) {
#Remove duplicate structures
my @stream = @{ $recordings_by_dur_attr{ $duration }{ $attr } };
my ( $mpls, $hms ) = ( $attr =~ /(\d+\.mpls), (\d+-\d+-\d+)$/ );
for ( my $i = 1; $i < @stream; $i++ ) {
#extract info from each stream
}
}
}