in reply to Re: Golfing Array_Pad
in thread Golfing Array_Pad

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

Replies are listed 'Best First'.
Re^3: Golfing Array_Pad
by holli (Abbot) on Jan 24, 2005 at 16:14 UTC
    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