develooper Front page | perl.fwp | Postings from December 2007

Re: bad code to good golf

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
December 9, 2007 15:54
Subject:
Re: bad code to good golf
Message ID:
475C8024.2050808@pobox.com
Uri Guttman wrote:
> is there any guarantee of evaluation order in arg lists? will the
> bless/splice always be executed before the pop?

I believe it is undefined, so it's not recommended that you do anything order
dependent in the argument list.  But it is stable.

As implemented, "complex" expressions are evaluated first, then simple ones.
This leads to classic oddities like this:

perl -wle 'sub foo { print join " ", @_ }  $i = 1;  foo($i, $i++, $i++)'
3 1 2

This is not specific to Perl, but I believe a C thing as well.


> 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.

You fell into the trap!  That's an improper constructor, can you tell us why?


-- 
Robrt:   People can't win
Schwern: No, but they can riot after the game.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About