Is there a way in Perl to make the presence of a duplicate hash key an error at declaration time?
For example, for a script like this:
test.pl
#!/usr/bin/perl
my %hash = (
'a' => 'valid',
'b' => 'valid',
'c' => 'valid',
'a' => 'duplicate'
);
I'd like to see something like this when it's run:
$ perl ./test.pl
duplicate hash key at ./test.pl line 7, near 'a' => 'duplicate'
Execution of ./test.pl aborted due to compilation errors.
Ideally I'd like to keep the hash declaration syntax the same. Is there any way to accomplish this?