Accessing an Array stored in a Hash, having difficulties
I am having a beast of a time with this. Hopefully someone can help me.
I have an array of strings: Code:
my @CategoryNames = (Armor, Augments, Weapons, Offslots, Misc); Code:
my %Weapons = And finally I have a Hash for Levels: Code:
my %LevelList = I am able to grab a random element out of CategoryNames fine using: Code:
$ItemType = $CategoryNames [rand @CategoryNames]; Code:
foreach $item (reverse sort keys %LevelList) { I am able to pull a single item out of any one of the arrays stored into Weapons fine using: Code:
$Weapons{$LevelCategory}[0]; Code:
my $Item = $ItemType{$LevelCategory} [rand @ItemType{$LevelCategory}]; Thank you for the help, and please excuse my shoddy Perl coding, still new at this! :) |
From your example, I am not sure where you are getting the ItemType hash of arrays from. Should it not be this?:
Code:
my $Item = $Weapons{$LevelCategory} [rand @Weapons{$LevelCategory}]; |
References in perl get kind of tricky, and when you ask for a nested list object, you're getting a reference.
Try something like this: (My examples are just command line demos so I can test outside of emu) Code:
#!/usr/bin/perl Code:
#!/usr/bin/perl |
Perfect, Tabasco, thanks. I originally tried a set up similar to the second one, but did not know you could nest an array in a hash in a hash. But now that I think of it, why wouldn't it? Learned something new with that reference deal. I'll have to read up on it.
Many thanks! :) |
All times are GMT -4. The time now is 06:47 AM. |
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.