On Thu, Sep 09, 2004 at 03:09:47PM +0200, Michele Dondi wrote: > On Thu, 2 Sep 2004, Larry Wall wrote: > > > And yes, an C<int1> can store only -1 or 0. I'm sure someone'll think of > > a use for it... > > Probably OT, but I've needed something like that badly today: "working" on > a japh that turned out to require mostly golfing skills (and not that I > have many, I must admit)... well, it would have been useful to have, say, > a pack template for 2-bits unsigned integers...
As an array index -1 and 0 give you the 2 ends. The perl5 code to alternately extract elements from the two eds of an array can be something like: my $end = 0; # -1 to start with right end while( @array ) { my $next = splice( @array, $end, 1 ); # use the $next element $end = -1 - $end; } Using int1 for $end, that last line can be changed in a variety of ways, such as: $end ^= 1; (except that the p5 ^= operator is written differently in p6) This is not a *good* use of int1 though. :-) --