[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] map: make a hash from an array



Given an array:

my @keepthese = qw(
  account_code adult_qty arrival_date child_qty depart_date gds_sys
  group_code lang_code prop prune_level rate_code rate_type room_type
  seamless_bk_code sga
);

Here's the slow way to make a hash out of it:

my %keepthese;
foreach (@keepthese) {
   $keepthese{$_} = 1;
}

Here's a faster way:

my %keepthese = map { $_, 1 } @keepthese;

HTH,

j