in reply to Re^2: Golfing Array_Pad
in thread Golfing Array_Pad

Yes I can.
use strict; use warnings; use Test::More tests => 5; my @x = 1 .. 5; is_deeply([p( 3, 'x', @x)], [ @x ]); is_deeply([p(-3, 'x', @x)], [ @x ]); is_deeply([p( 7, 'x', @x)], [ @x, 'x', 'x' ]); is_deeply([p(-7, 'x', @x)], [ 'x', 'x', @x ]); @x = (); is_deeply([p(-4, 'x', @x)], [ 'x', 'x', 'x', 'x' ]); sub p {($a,$b,@x)=@_;@_=($b)x(abs@x-abs$a);@_=abs$a>@x?$a<0?(@_,@x):(@ +x,@_):@x}
Update:
oh dear, @x is a global. silly, me.

holli, regexed monk

Replies are listed 'Best First'.
Re^4: Golfing Array_Pad
by demerphq (Chancellor) on Jan 24, 2005 at 16:20 UTC

    Yes i can.

    use strict; use Test::More tests => 5; my @x = 1 .. 5;
    ^^^^^^^^^^^^^^^

    Er, no, it can't, at least not in the code you originally posted. The followup code of course declares @x as a file level lexical, which kinda answers your original question doesn't it.

    ---
    demerphq