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

*question near end, but explanation needed to understand what I'm trying to do*

I'm using CGI::Sessions with my site.
My site has many areas & sub areas. Each of which have different access requirements, etc.

When a user logs in, I would like to send a hash to the session that will then contain another hash.

The first hash's keys will be specific to each subdomain of my site. The hashes reference to by the keys will then hold the access permissions for that subdirectory (each key in the subhash will be for a directory and contain info for the user's access).

ie.
sports.sitename.com
- football
- basketball
- soccer
animals.sitename.com
- dogs
- cats
- birds
games.sitename.com
- tetrinet
- marioworld
- counter-strike
others.sitename.com
- random
- stuff

The session will contain:
- userID = user id
- alias = name of user
- access = 0 or 1... (1 = logged in)
then also a :
- access = { %sports => { football => 1, soccer => 1 }, %games => { counter-strike => 1 } };

NOTE: the only data that will be stored is when a user DOES have access to a subdomain and DOES have access to a folder.
from the value of 'access' above, you can see the user only has access to a folder under the sports & games subdomains, so only those two are stored in the session.


****************************************************
My question is:
if I have an array as follows:
@sports = (football, soccer);
@games = (counter-strike);

how can I create the hash that will be stored in 'access'?


As always, I appreciate your patience with my steep learning curve ;-P

Any help/feedback would be greatly appreciated!


Stenyj

P.S. An example of what my deluded mind is kind of trying to do:
my @sports = ('soccer', 'football'); my @games = ('tetrinet', 'counter-strike'); my %access; foreach my $s (@sports) { $access{sports} .= {$s => 1}; } foreach my $g (@games) { $access{games} .= {$g => 1}; } my $empty; my $session = new CGI::Session(undef, $empty, {Directory=>"c:/apache/c +gi-bin/tmp"}); $session->param("access", %access);

Replies are listed 'Best First'.
Re: Hash within a hash from dynamic data.. how?
by revdiablo (Prior) on Jul 03, 2004 at 23:44 UTC

    Instead of:

    $access{sports} .= {$s => 1};

    You probably want:

    $access{sports}{$s} = 1;

    You might want to see perldsc for a nice doc about datastructures, and perlreftut for a nice introduction to references.