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

I have a project that requires a very large number of hashes. I would like to place these hashes in a seperate file as a package and use them in the main program but:

%hash = packagename::%hash;

but that gives a syntax error. So I tried escaping the "%":

%hash = packagename::\%hash;

but that give an error specifically with the ::\

any ideas? thanks

Replies are listed 'Best First'.
Re: accessing package variables
by chromatic (Archbishop) on Oct 20, 2000 at 20:32 UTC
    Try %packagename::hash.

    The punctuation symbols have more to do with context than the actual variable names. You could refer to me as Mr. industries, or Mr. chromatic industries, but never as chromatic Mr. industries.

    Dumb example, but it works for me.

Re: accessing package variables
by Trimbach (Curate) on Oct 20, 2000 at 20:35 UTC
    Put the % in front of your packagename, as in:
    %hash = %pacakagename::hashname;
    That'll work.

    Gary Blackburn
    Trained Killer

Re: accessing package variables
by adamsj (Hermit) on Oct 20, 2000 at 20:33 UTC
    I don't suppose you've tried this:

    %packagename::hash

    That should help.

Re: accessing package variables
by nop (Hermit) on Oct 21, 2000 at 23:19 UTC
    Alternatively, rather than having a (painfully?) large number of hashes, toss them all one super hash, where the first 'dimension' of the hash indicates what it is...
    $x{'hashname'}{'hashdim1'}{'hashdim2'} = 'blah'
    rather than
    $hash1{'hashdim11'}{'hashdim12'} = 'blah' $hash2{'hashdim21'}{'hashdim22'} = 'bluck' etc