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

前端 未结 4 536
夕颜
夕颜 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:04

    For the first one, try

    my %hash = 
    ( "currency_symbol" => "BRL",
      "currency_name" => "Real"
    );
    print Dumper(\%hash);
    

    The result will be:

    $VAR1 = {
              'currency_symbol' => 'BRL',
              'currency_name' => 'Real'
            };
    

提交回复
热议问题