in reply to Re: Problem emulating built-ins like map and grep.
in thread Problem emulating built-ins like map and grep.
In truth, the use Carp; (and the associated test for oddness) was tacked in the just for posting, it would always appear at the top of the program in real code. Does use have a huge runtime cost? I was under the impression that use was effectively a compile time directive?
Personnally, coming from a C-background, I find ... if @_ & 1; an eminently readable and obvious test for 'oddness'. It wasn't done as an optimisation, it's just the clearest test for oddness that I know of. YMMV.
The version of the code in my private library doesn't contain the oddness test at all. Though I think I will go back and add it, it already has a use Carp; atthe top anyway. I'll still use @_ & 1 though :)
the while loop still avoids building a 1 .. @_ / 2 list, thus still saving effort.
Aren't you just trading a >> and building one list, for building a local array and the then converting that back to list to return it? I doubt there's much in it in performance terms either way, but using an unnecessary intermediate variable seems very un-Aristotle-like:)
re: # let's remove the multiple calls to print() and make the use of a map justifiable, shall we?
As you pointed out yourself in your earlier post, your alternative wouldn't have demonstrated the problem I was describing, which was the only purpose of the code.
Examine what is said, not who speaks.
The 7th Rule of perl club is -- pearl clubs are easily damaged. Use a diamond club instead.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Problem emulating built-ins like map and grep.
by Aristotle (Chancellor) on Jan 22, 2003 at 23:39 UTC | |
by BrowserUk (Patriarch) on Jan 23, 2003 at 00:28 UTC | |
by Aristotle (Chancellor) on Jan 23, 2003 at 07:40 UTC |