in reply to Re: Re: Problem emulating built-ins like map and grep.
in thread Problem emulating built-ins like map and grep.
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?You are building two lists, one as the dummy input to map, and one as its return value. The while loop makes the latter explicit and renders the former superfluous. You may have a point in that there's a hidden second list built to return the array contents (I'm not sure about that) - that just means the solutions are even though.
I doubt there's much in it in performance terms either way, but using an unnecessary intermediate variable seems very un-Aristotle-like:)
You're right. And I say that because I don't like either solution much. I prefer the while approach better here since it reads more naturally, as opposed to the dummy list "hack" you need for map. All that said and done though, it really is an ugly shortcoming of Perl that all of the list oriented operators can only step through a list one element at a time. And because that's true for all of them, homegrown solutions are inevitably ugly too.
Finally, it occured to me that if you insist on map, you could generate the dummy list more economically since you don't actually use its elements:
Esp the latter will probably take a lot less memory to process very large lists (though still a significant amount).map { ... } (1)x(@_/2); # or even map { ... } (undef)x(@_/2);
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re^3: Problem emulating built-ins like map and grep.
by BrowserUk (Patriarch) on Jan 23, 2003 at 00:28 UTC | |
by Aristotle (Chancellor) on Jan 23, 2003 at 07:40 UTC |