Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/perl
# https://stackoverflow.com/questions/48529062/hash-value-overwrite-due-to-similar-keys
use Data::Dumper;
my $mapping_table = {
'Exemplare' => 'copies',
'Seiten' => 'pages',
'Statushinweis' => 'status',
'Serie von' => 'number_of',
'ISBN/Barcode-Nr.' => 'ISBN_barcode',
'Status' => 'status',
};
my $data = [
{
'Exemplare' => '1',
'Seiten' => '0',
'Statushinweis' => 'Statushinweis',
'ISBN/Barcode-Nr.' => '3-551-01561-9',
'Serie von' => '4',
'Status' => 'Gesucht'
},
{
'Exemplare' => '4',
'Seiten' => '111',
'Statushinweis' => '',
'ISBN/Barcode-Nr.' => '3-551-01561-9',
'Serie von' => '4',
'Status' => 'Vorhanden'
}
];
my $mapped_data = [];
foreach my $issue ( @$data ) {
my %tmp_hash;
foreach my $key (sort keys %$mapping_table) {
$tmp_hash{$mapping_table->{$key}} = $issue->{$key};
}
push @$mapped_data, \%tmp_hash;
}
print Dumper $mapped_data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.