DEV Community


Discussion on: Way Too Many IF-THEN-ELSEs? Try a Lookup Table

billcosta profile image
Bill Costa Author

You bet! I glossed over that in the code example in this article because I wanted the code to be as clear as possible for non-Perl folks. I'm hoping that people who are interested in the Perl aspect will take the time to look at the demo. It uses exists() instead of defined() when testing against the table for just that reason. In the demo I also wanted to avoid dependancies. But at some point I would like to circle back and explore if the lookup table can be made read-only after it is built, which would be better still. I just need to take the time to explore modules like ReadonlyX.

grinnz profile image
Dan Book • Edited

ReadonlyX is a great option for this. Note that exists and defined both still autovivify any intermediate structures - e.g. if you are looking at $foo->{bar}{baz} then $foo will be autovivified to {bar => {}} regardless of what the end check is (the final element will not be vivified unless assigned to). Two options for avoiding this are autovivification and my Data::DeepAccess.