Bod has asked for the wisdom of the Perl Monks concerning the following question:
This follows on from Indirect Object Syntax but it is a different question so it gets its own place!
In doing some of the reading that came out from Indirect Object Syntax, especially this on SO from ikegami, I have noticed that often (but not always) hash keys are not quoted literals but barewords. Given the potential for confusion that has been shown from Indirect Object Syntax, it seems that this is another place where confusion could arise.
I have noticed this before but never really thought anything of it.
I never write it like that. I always quote it unless the key is non-constant.my $value = $hash{ key };
my $value = $hash{'key'}; my $value = $hash{ $key_value }; my $value = $hash{"st_$id"};
Is there a difference between $hash{ key } and $hash{'key'}?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Quoting hash keys
by eyepopslikeamosquito (Archbishop) on Nov 09, 2021 at 06:44 UTC | |
by Bod (Parson) on Nov 10, 2021 at 01:19 UTC | |
by hippo (Archbishop) on Nov 10, 2021 at 09:26 UTC | |
|
Re: Quoting hash keys
by haukex (Archbishop) on Nov 09, 2021 at 08:41 UTC | |
by eyepopslikeamosquito (Archbishop) on Nov 09, 2021 at 09:52 UTC | |
by haukex (Archbishop) on Nov 09, 2021 at 11:23 UTC | |
|
Re: Quoting hash keys
by kcott (Archbishop) on Nov 09, 2021 at 05:48 UTC | |
|
Re: Quoting hash keys
by LanX (Saint) on Nov 09, 2021 at 00:52 UTC | |
by Bod (Parson) on Nov 10, 2021 at 01:16 UTC | |
|
Re: Quoting hash keys
by ikegami (Patriarch) on Nov 10, 2021 at 17:41 UTC |