Paul,
I am a Perl newbie, but I am employed as a Visual C++ and Visual Basic
programmer. I'm having trouble figuring out what your construct is
doing. For reference, here it is:
> @website[
> map $_->[0],
> sort { $b->[1] <=> $a->[1] }
> map [ $_, $array[$_] ],
> 0 .. $#array
> ] = 1 .. @array;
Let me see if I can figure out what this is doing, and I would
appreciate it if you could fill in the holes. Hmmm... On second
thought, I am more baffled than I thought I was. Let's see where I can
get anyway.
1. "@array" used in numeric context returns the number of elements in
the array. So, you are assigning the numbers 1 through n to elements
of the @website array.
2. The order in which the elements of the @website array are filled is
determined by the code within the brackets. Code within brackets is a
completely new concept to me.
3. There are two Perl statements withing @website's brackets, both of
them being map calls. I can't explain why there aren't any semicolons
in there. If this is incorrect, my second guess is that there is a
single map statement in there that has another map statement inside it.
No, I'm not on the right track. It's a map that uses a sort that uses
a map.
4. The innermost map statement is "map [ $_, $array[$_] ], 0 ..
$#array. This is of the "map EXPR, LIST" form, which returns a list
built by applying the expression to the list. Aside from knowing that
$_ is the default argument, I do not know what "[ $_, $array[$_] ]"
does.
5. The sort statement sorts the list returned by the inner map from
highest to lowest value. I've seen the "$b <=> $a" syntax before (but
only in a book). I don't know what the "[1]"s are in there for.
6. The outer map statement applies "$_->[0]" to the list returned by
the sort. I do not know what this means either.
7. If we assume an input array of (8, 1, 7, 2, 6, 3, 5, 4), the
complete statement would first put "1" in $websites[0], then put "2" in
$websites[2], then put "3" in $websites[4], then put "4" in
$websites[6], then put "5" in $websites[7], then put "6" in
$websites[5], then put "7" in $websites[3], and then put "8" in
$$websites[1].
OK, how far off am I?
Thanks!
Rob
__________________________________________________
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now.
http://mailplus.yahoo.com
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]