Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Perl Module Problems

by davidov0009 (Scribe)
on Sep 24, 2006 at 15:02 UTC ( [id://574604]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl Module Problems
in thread Perl Module Problems

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: Perl Module Problems
by Hue-Bond (Priest) on Sep 24, 2006 at 15:27 UTC
    my @maps_$game = HLDS::GameMaps("$game");

    You already were told that it's a bad idea to use a variable as a variable name. In this case it's better to use a hash:

    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;

    --
    David Serrano

      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?
        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://574604]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2024-04-18 02:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found