In article <[EMAIL PROTECTED]>, Stuart 
White wrote:

> This does make it clearer, but not entirely.  Is this

> James wrote:
>> This is a common Perl technique, often used with a
>> hash named '%seen'
>> because that's exactly what it's keeping track of.
>> $1 is where you
>> were capturing your names, I just made that the key
>> to the hash and the
>> ++ just increments the value.  In long form it's
>> $linehash{$1} =
>> $linehash{$1} + 1.  In english that's, "Add one to
>> the value stored in
>> %linehash at $1, replacing the old value."  The
>> first time a name is
>> seen it's value will be undef, which conveniently
>> numifies to 0.

Hi Stuart,

This is so useful and easy that it's worth really understanding. Here's a 
non-programming metaphor:

As each player makes a shot he calls out his name ($1): "smith". The 
scorekeeper says, "ah, smith ($score{smith}) - let's add 1 to Smith's total 
attempts ($score{smith}++). This goes on each time an attempt is noted: "Ah 
Smith again - add another one to Smith's score ($score{smith}++).

At the end, along comes Jone's mother, who asks, "How did my son do?" "Let's 
see ($score{jones} )  - oh bad news I don't even see his name in the list 
of attempts, so that must mean zero."

So the key is the name and the value (being incremented each time) is the 
number of attempts.

The key could also be attempted logins, or the number of times the word 
"right" occurs in the Bible, Bush's speeches, etc.)

Cool, huh?  (Okay no more metaphors - I promise)

-- 
Kevin Pfeiffer
International University Bremen

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to