There's more than one way to do things | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
My next problem is this: map {$_->[0]}. I know that map is operating on $_[0] (I think) but what is this: ->[0] ???.
I think you need to get the idea of refrences to arrays and arrays. Consider Now if I need to get an element of @array directly I use this syntax: but if I want to get it through the refrence i have to do The -> tells perl to treat the '$array' as the SCALAR with the name 'array' and not as another type with the same name, the [] tells perl that the scalar refers to an array and not a hash. The same thing applies to the variables $_ @_ %_ So in the ST you wrap you data and your keys, one at a time, in anonymous arays (Notice the square brackets in the rightmost map body). Then SORT goes through each of the elements, which are refrences to arrays, and has to dereference them to get at the keys, finally the left most map takes of the anonymous array 'wrapper' and throws it away, returning the sorted list.
HTH Yves In reply to Re: Re: Sorting strings
by demerphq
|
|