but foo was alone. so bar was created.#!/usr/bin/perl -w use strict; my %foo = ( camshaft => 'lumpy', gearbox => 'shifty', drivetrain => 'speedy', smokestack => 'dirty', lights => 'bright eyes', );
but bar was different... and empty. foo wants to understand bar, and a map was made...my %bar; @bar{ qw/camshaft gearbox1 the_drivetrain _other/ } = '';
still, bar was empty, so along comes schlep to help...my %map_foo_to_bar = ( camshaft => 'camshaft', gearbox => 'gearbox1', drivetrain => 'the_drivetrain', smokestack => 'my_smokestack', junkyard => '_junkyard', );
so it is written, so it shall be done.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;
~Particle ;Þ
In reply to Re: Bulk Hash Assignment
by particle
in thread Bulk Hash Assignment
by tadman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |