my @games=qw( cstrike dod czero gearbox ricochet dmc tfc valve );
my %maps;
foreach my $game (@games) {
$maps{$game} = HLDS::GameMaps("$game");
}
## Visualize the data structure
use Data::Dumper; print Dumper \%maps;
| [reply] [d/l] [select] |
So that has created a hash named %maps, storing the arrays returned by my subroutine?
My sub returns an array named @maps regardless of the arg passed to it, does create a conflict?
How do I access these arrays that are stored within a hash?
| [reply] |
It should have been $maps{$game} = [ HLDS::GameMaps("$game") ]; (Note the square brackets). The square brackets create an array from the list returned by GameMaps, and returns a reference to that array. The reference is then stored in the hash. @{$maps{$game}} is the array of maps for game $game.
| [reply] [d/l] [select] |