Hash Constants in Perl

I have a situation where I have an application and it maps to a directory I need to process in a zipfile. The mapping is quite simple:

CWA => "Financial",
PIP => "",
IFA => "IFA",
VDX => "Financial,

That is, if the name of the file begins with CWA, I know the directory I have to munge is under Financial. If the file name begins with a IFA, I know the directory name is IFA. I'd like to set this up as a hash (easy enough), but since these values don't really change, I'd like to setup this key => value mapping as a hash constant.

I don't believe this is possible, so I'd like to do the next best thing. What would that be? Or, can you setup a hash constant?

I'm thinking of writing a subroutine where you pass a parameter and it returns the correct value. After all, it's really the way constants themselves work, and it'd guarantee that the relationships between the keys and values don't change through out the program.

Or, I can simply declare the key => value relationship in the beginning of my program and hope that the key => value pairs aren't modified by something. This would be easier to read, and easier to modify if you have to since it's on the very top of my source code.

What's the best way to implement a key => value constant?

11
задан David W. 6 December 2010 в 19:16
поделиться