How do I initialize values in a hash without a loop?

前端 未结 4 534
夕颜
夕颜 2021-02-05 10:37

I am trying to figure out a way to initialize a hash without having to go through a loop. I was hoping to use slices for that, but it doesn\'t seem to produce the expected resul

4条回答
  •  伪装坚强ぢ
    2021-02-05 11:21

    use strict;
    use warnings;  # Must-haves
    
    # ... Initialize your arrays
    
    my @fields = ('currency_symbol', 'currency_name');
    my @array = ('BRL','Real');
    
    # ... Assign to your hash
    
    my %hash;
    @hash{@fields} = @array;
    

提交回复
热议问题