Skip to content

Instantly share code, notes, and snippets.

@shoorick
Created October 22, 2018 19:15
Show Gist options
  • Save shoorick/ffd60e900e09b413581f3c475ee2ffba to your computer and use it in GitHub Desktop.
Save shoorick/ffd60e900e09b413581f3c475ee2ffba to your computer and use it in GitHub Desktop.
#!/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