in reply to Throw compilation error(or warning) if duplicate keys are present in hash
There is no duplicate key at compile-time — the list is only created and assigned to the hash at run-time — so the answer to your literal question is "no".
However, it is possible to write an opcode checker that detects the posted code pattern at compile-time. (For example, module autovivification uses an opcode checker to not only examine opcodes, but to replace them.) This approach would probably be better to add a *run-time* warning.
A better approach to detecting the situation at compile-time would be to write a Perl::Critic rule to look for the code pattern you posted.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Throw compilation error(or warning) if duplicate keys are present in hash
by I_love_perl (Novice) on Nov 24, 2011 at 09:18 UTC | |
by ikegami (Patriarch) on Nov 25, 2011 at 03:54 UTC | |
by petdance (Parson) on Nov 27, 2012 at 21:20 UTC |