sub unpack2hash { my ($template, $source) = @_; my $hash = {}; foreach(split / /,$template) { my ($temp,$type,$var) = split /:(.)/; if($type eq '@') { my @r = unpack $temp, $source; $hash->{$var} = \@r; my $pack = pack $temp, @r; substr $source, 0, length $pack, ''; }elsif($type eq '$') { my $r = unpack $temp, $source; $hash->{$var} = $r; my $pack = pack $temp, $r; substr $source, 0, length $pack, ''; } else{ die "need context type\n" } } return $hash; } #### my $h = unpack2hash(join(' ',( 'l:$songid', 'c8:@signature', 'l:$genre', 'f:$bpm', 's3:@level', 's:$unk', 'l12:@unk2', 'a24:$genres', 'l2:@unk3', 'a32:$title', 'a32:$subtitle', 'a32:$artist', 'a32:$noter', 'a32:$musicfile', 'l:$jpg', 'l3:@unk4', 'l4:@notepos' )), $data);