in reply to Quick easy question: What does $i mean?

Thanks, I believe that it is the loop name here is a specific example
my ($i); for ($i = 0; ($i < int (@commandsProperOrder)); $i += 2) { $commandsProperOrder{$commandsProperOrder[$i]}= $commandsProperOrder[$i + 1]; }
this code is full of $i's

Replies are listed 'Best First'.
Re^2: Quick easy question: What does $i mean?
by QM (Parson) on Sep 23, 2005 at 23:05 UTC
    First off, you'll want to learn how to post here. If you put your code between "<code>" and "</code>" tags, then normal code punctuation is escaped for you. So this:
    my ($i); for ($i = 0; ($i < int (@commandsProperOrder)); $i += 2) { $commandsProperOrder{$commandsProperOrder$i} = $commandsProperOrder$i + 1; }
    looks like this:
    my ($i); for ($i = 0; ($i < int (@commandsProperOrder)); $i += 2) { $commandsProperOrder{$commandsProperOrder[$i]} = $commandsProperOrder[$i + 1]; }
    (OK, I had to break some lines because of the long variable names, but otherwise it came out as typed.)

    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:

    %commands = @commands;
    No $is, etc., just Perl magic.

    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