%hash = (
name => 'Rhesa',
fruit => 'Mango',
dog => 'Spot',
cat => 'Stofje',
);
####
%pets = (
dog => 'Spot',
cat => 'Stofje',
);
####
%pets = (
dog => $hash{dog},
cat => $hash{cat},
);
####
my @animals = qw( dog cat );
my %pets;
@pets{ @animals } = @hash{ @animals };
####
%pets = map { $_ => $hash{$_} }
qw( dog cat );
####
sub hash_slice {
my ($hr, @k) = @_;
return map { $_ => $hr->{$_} } @k;
}
# or using a slice (might be more efficient, but doesn't read as nicely)
sub hash_slice {
my ($hr, @k) = @_;
my %ret;
@ret{@k} = @$hr{@k};
return %ret;
}
# use like this:
%pets = hash_slice( \%hash, qw( dog cat ) );
####
@headers = qw(
firstname lastname
address_line1 address_line2 city zip state country
order_number
title bookcode isbn
quantity
);
####
# %orderline comes from the csv
my $customer = Customer->find_or_create({
firstname => $orderline{firstname},
lastname => $orderline{lastname},
});