#!/usr/bin/perl -w
use strict;
my %foo = (
camshaft => 'lumpy',
gearbox => 'shifty',
drivetrain => 'speedy',
smokestack => 'dirty',
lights => 'bright eyes',
);
####
my %bar;
@bar{ qw/camshaft gearbox1 the_drivetrain _other/ } = '';
####
my %map_foo_to_bar = (
camshaft => 'camshaft',
gearbox => 'gearbox1',
drivetrain => 'the_drivetrain',
smokestack => 'my_smokestack',
junkyard => '_junkyard',
);
####
sub schlep($$$)
{
my( $map_ref, $from_ref, $to_ref ) = ( shift, shift, shift );
for( keys %{ $from_ref } )
{
$to_ref->{ $map_ref->{$_} } = $from_ref->{$_}
if( exists $map_ref->{$_} && exists $to_ref->{ $map_ref->{$_} } )
}
}
schlep(\%map_foo_to_bar, \%foo, \%bar);
use Data::Dumper;
print Dumper \%bar;