Re: bad code to good golf
Uri Guttman <[email protected]> Sun, 09 Dec 2007 13:39:28 -0500
| Newsgroups | gmane.comp.lang.perl.fun |
|---|---|
| Message-ID | <[email protected]> |
>>>>> "rw" == robert wilson <[email protected]> writes: rw> On Sunday 09 December 2007, Michael G Schwern (Michael G Schwern rw> <[email protected]>) wrote: >> sub new {bless{@_[1..$#_]},shift} >> >> Was my first shot at 23. Then I figured I could knock off that range op... rw> my first shot was 23 also... rw> sub new{($a,@b)=@_;bless{@b},$a} rw> then i came up with this 21 a few seconds later: rw> sub new{bless{splice@_,1},pop} rw> i think that's the best i can do... i'll be very impressed if anyone does rw> better than 21. you and marcus are tied for first with the same answer. is there any guarantee of evaluation order in arg lists? will the bless/splice always be executed before the pop? my longer but amusing answer is this: sub new { bless{reverse%{{reverse@_}}} } it is not warning safe and it leaves '' => CLASS in the hash. but it has no temp vars, calls to splice or shift. uri -- Uri Guttman ------ [email protected] -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org