[Charlotte.PM] find index of array element

William McKee william at knowmad.com
Thu Mar 24 03:09:59 PST 2005


On Wed, Mar 23, 2005 at 12:45:24PM -0500, Dale Lancaster wrote:
> I think the original requirement was to return the index in the original 
> list of the matching element, not the actual element.  I don't believe the 
> below accomplishes that.

You're right, it doesn't match the requirements. I was thinking form
(she used the keywords grep and array) over function.


> Funny, that your example would actually produce the same answer in my
> test code, but only because perl is subtracting 1 from the value of
> the element in the matching array.

Yeah, that's sheer coincidence. Substituting chars for numbers makes it
very clear.


> This is probably as fast or faster than my original code and of course 
> doesn't parse the whole array and is much more readable and maintainable 
> (and extensible).

Although map and grep are very cool techniques, it's interesting to find
ways in which they are not as efficient as just writing it out the long
way (like I used to do before I understood these functions).

Your point reminds me of a recent article I was reading by ESR[1] while
looking at the various F/OSS CMS products available. One of the benefits
that he tauts when comparing Python to Python is the compactness of the
Python language.

I can see where there is some benefit to having to remember fewer
commands to get your work done. At some point though, you're going to
hit the limitations of the language. Sure, it's hard to fit all of
Perl's functions much less the growing mass of modules on CPAN into
your head. All-in-all, I'd prefer the richer language to the compact
language. I presume most folks on this mailing list are of the same
opinion; anyone care to proffer a counter-argument (even if you're not
beholden to it, it might make for an interesting discussion).


William

[1] http://www.linuxjournal.com/article/3882

-- 
Knowmad Services Inc.
http://www.knowmad.com


More information about the charlotte mailing list