in reply to Re^2: splitting directly to hash
in thread splitting directly to hash

  1. split breaks down the string into a list of values (('1', '2', '3', '4', '5')).
  2. For every element in the list,
    1. map transforms the element into a list consisting of the element and undef. (('1', undef)).
  3. map returns a list consisting of the aggregation of all the smaller lists (('1', undef, '2', undef, '3', undef, '4', undef, '5', undef)).
  4. The list returned by map is assigned to the hash.

By the way, here's a shorter solution:

my $keys = '1 2 3 4 5 6'; my %hash = $keys =~ /(\S+)()/g;

To use an environment variable, substitute $keys with $ENV{varname}.