我想在 Perl 中做以下 Ruby 代码的等价物:
class Foo
MY_CONST = {
'foo' => 'bar',
'baz' => {
'innerbar' => 'bleh'
},
}
def some_method
a = MY_CONST[ 'foo' ]
end
end
# In some other file which uses Foo...
b = Foo::MY_CONST[ 'baz' ][ 'innerbar' ]
也就是说,我只想声明一个常量、嵌套的哈希结构,以便在类中和外部使用。如何?