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

Re: Quick easy question: What does $i mean?

by sicone (Initiate)
on Sep 23, 2005 at 21:36 UTC ( [id://494691]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found