in reply to Golfing Array_Pad

this is my best attempt (and my first golf, so please be kind ,):
sub p { my($a,$z,@x)=@_; my @n=($z)x(abs @x-abs $a); @n=abs $a>@x?$a<0?(@n,@x):(@x,@n):@x; }
It passes strict; and warnings;

Update:
slightly optimized(71; less whitespace, stolen tricks ,)
sub p {($a,$b,@x)=@_;@_=($b)x(abs@x-abs$a);@_=abs$a>@x?$a<0?(@_,@x):(@ +x,@_):@x}
Why can i omit "my" here?

holli, regexed monk

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

    Why can i omit "my" here?

    You can't.

    Global symbol "@x" requires explicit package name at c:\temp\a_sub.pl +line 8. Global symbol "@x" requires explicit package name at c:\temp\a_sub.pl +line 8. Global symbol "@x" requires explicit package name at c:\temp\a_sub.pl +line 8. Global symbol "@x" requires explicit package name at c:\temp\a_sub.pl +line 8. Global symbol "@x" requires explicit package name at c:\temp\a_sub.pl +line 8. Global symbol "@x" requires explicit package name at c:\temp\a_sub.pl +line 8. Execution of c:\temp\a_sub.pl aborted due to compilation errors.
    ---
    demerphq

      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

        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