in reply to Re: Quick easy question: What does $i mean?
in thread Quick easy question: What does $i mean?
my ($i); for ($i = 0; ($i < int (@commandsProperOrder)); $i += 2) { $commandsProperOrder{$commandsProperOrder$i} = $commandsProperOrder$i + 1; }looks like this:
(OK, I had to break some lines because of the long variable names, but otherwise it came out as typed.)my ($i); for ($i = 0; ($i < int (@commandsProperOrder)); $i += 2) { $commandsProperOrder{$commandsProperOrder[$i]} = $commandsProperOrder[$i + 1]; }
Second, I'd guess that the array @commands has a list of pairs, and that the code is trying to put those pairs into the hash %commands. Normally you want to know (or check) that your array is appropriate for this, but hash stuffing is more easily done with:
No $is, etc., just Perl magic.%commands = @commands;
This works because a list can be assigned to a hash, and it will (sometimes) do the right thing. (It's certainly no worse than the code you posted.) [When you're ready, just ask, someone will tell you when and why it doesn't do the right thing.]
-QM
--
Quantum Mechanics: The dreams stuff is made of
|
|---|