Hash Array in Perl Question
I got this little plugin i'm mucking around, this is just a snippet, but the idea is still there:
The problem: quest::say always just says "Requires " once, and never iterates/echos anything of note. pastebin probably easier to read. http://pastebin.com/NGwDt2Rj Code:
sub DoArmorHandin { |
Change this:
Code:
foreach my $entry ($armor_list[$zoneid][$class]) { Code:
foreach my $entry (@{$armor_list[$zoneid][$class]}) { |
That change uses Perl's dynamic type casting and allows the foreach to recognize it as an array rather than a singular variable.
|
I was still having some peculiar issues, that aside though.. my next issue is..
I'm trying to check_handin and it seems to always be empty with itemcount, so, i'm trying to pass itemcount, similar to how check_handin does it. Code:
plugin::velious_armor_handin($zoneid, $cash, $client->GetClass(), \%itemcount) Code:
sub velious_armor_handin { |
Would be curious to see the hash itself as it looks like a hash of arrays of arrays, however, at a very quick glance as I'm just perusing with limited time atm:
Code:
for $x (0...6) { I assume this hash that you're concocting contains quest hand-in/reward? |
Didn't even see that, but oddly, perl is OK with three dots. I'll change it up to ensure no other side effects.
http://codepad.org/7A83V6CT The challenge/solution I originally posted I ended up re-approaching and iterating the $armor_list as an array, and then grabbing the hash data as seen on the bottom example. My only snag now is that I'm trying to transfer the %itemcount hash to plugin::check_handin() via another function, plugin::velious_armor_handin() and for some reason, passing the variable from function to function is not doing pointer refs. May end up picking up a programming book about perl, but figured perl experts can peek and be like "Do X instead of Y", and save me a ton of time of fiddling and google research that inevitably is probably a 2 line fix. |
from http://perldoc.perl.org/perlref.html
"References are easy to use in Perl. There is just one overriding principle: in general, Perl does no implicit referencing or dereferencing. When a scalar is holding a reference, it always behaves as a simple scalar. It doesn't magically start being an array or hash or subroutine; you have to tell it explicitly to do so, by dereferencing it." |
Thanks c0ncrete. So the answer to my question is: \%{$itemref}
Code:
sub velious_armor_handin { ghanja sent me a PM that informed shift is destructive and pulls data out of the argument list @_ so, I will keep that in mind while I finish fixing other issues. This is all complete, and I posted the solutions to my question on each part, for anyone else who may have similar questions. Thanks for your help guys. |
it's been a very long time since i've been eyeball deep in perl, but that looks syntactically correct at least. i don't have my old work to reference at the moment (at the office currently), but i'll be digging up some old stuff where i was using references all over the place when i get back to the house in a few hours.
|
my tl;dr to answer my own question:
perl == c++ /$var == &var {$var} == *var |
All times are GMT -4. The time now is 07:15 PM. |
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.