I don't know the map function.

Teddy,
[EMAIL PROTECTED]

----- Original Message -----
From: "drieux" <[EMAIL PROTECTED]>
To: "cgi cgi-list" <[EMAIL PROTECTED]>
Sent: Monday, May 20, 2002 7:25 AM
Subject: Re: Counting the elements of an array



On Sunday, May 19, 2002, at 06:29 , Octavian Rasnita wrote:

> I couldn't understand anything, but thank you very much! :-)

my apologies - how can I help make it more understandable?

> I could use the other solutions very easy, but now I have another problem.

better a solution than None!

> I should try to understand your code.
[..]
> http://www.wetware.com/drieux/pbl/BenchMarks/uniqCounts.txt
>
> ok, so my OCD is benchmarking - but I would like to offer
> what I think may be a bit quicker - if speed is your Need...
>
>    #------------------------
>    #
>    sub haveMap {
>      my (@list) = @_;
>      my %seen = ();
>
>      map {$seen{$_}++} @list;
>
>      \%seen ;
>
>    } # end of haveMap

this is a bit of squirrelly code in the sense that one
has to feel at home with map,

cf perldoc -f map

and to be honest - to me it is VOODOO - I really do not
get it... in this case

map {$seen{$_}++} @list;

would unwrap as

for(@list) {
$seen{$_} += 1;
}

or more verbose it would read as

for(@list) {
if (exists($seen{$_}) {     # if such a thing is there increment it
my $tmp = $seen{$_};
$seen{$_} = $tmp + 1 ;
}else{ # else assign it an initial value of one
$seen{$_} = 1 ;
}
}

as long as you can cope with the idea of

(undef + 1) == 1

which is the initial condition - and we avoid it because
the '++' operator in this case is 'majikal'....


ciao
drieux

---



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




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

Reply via email to