eXile has asked for the wisdom of the Perl Monks concerning the following question:

Hi, here is a sample of my debug session:
DB<11> x __PACKAGE__ 0 'Item::Mimepart' DB<12> x $Cache::MaxSize{'Item::Mimepart'} 0 2000 DB<13> x $Cache::MaxSize{__PACKAGE__} 0 undef
From 11 and 12 I thought $Cache::MaxSize{__PACKAGE__} = 2000 (at least that is what I want it to be), but it's undef. What am I missing?

Replies are listed 'Best First'.
Re: usage of __PACKAGE__
by borisz (Canon) on Jul 20, 2004 at 16:45 UTC
    what you need is tell perl that your key name is not __PACKAGE__.
    $Cache::MaxSize{ +__PACKAGE__ } = 2000;
    or
    $Cache::MaxSize{ '' . __PACKAGE__ } = 2000;
    Boris
Re: usage of __PACKAGE__
by blokhead (Monsignor) on Jul 20, 2004 at 16:47 UTC
    $ perl -MO=Deparse -e '$hash{__PACKAGE__} = 1' $hash{'__PACKAGE__'} = 1;
    __PACKAGE__ gets treated as a string, as does any bareword (keyword or not) that you use to index a hash (think $foo{shift}). The easiest fix is adding a plus sign to make it an expression instead of a string.
    $ perl -MO=Deparse -e '$hash{+__PACKAGE__} = 1' $hash{'main'} = 1;

    blokhead