Why are some hashes initialized using curly braces, and some with parentheses?

前端 未结 3 428
予麋鹿
予麋鹿 2021-02-05 08:42

I\'m looking at the following code demonstrating nested hashes:

my %HoH = (
    flintstones => {
        husband   => \"fred\",
        pal       => \"b         


        
3条回答
  •  半阙折子戏
    2021-02-05 09:22

    The essential difference (....) is used to create a hash. {....} is used to create a hash reference

    my %hash  = ( a => 1 , b => 2 ) ;
    my $hash_ref  = { a => 1 , b => 2 } ;
    

    In a bit more detail - {....} makes an anonymous hash and returns a reference to it wich is asigned to the scalar $hash_ref

    edited to give a bit more detail

提交回复
热议问题