in reply to Applying an array to a function

What BrowserUk said is what I think as well. You do not need the repeat sub, and if you do for something else, you can shorten it like this:
sub repeat { my ($n,$x) = @_; my $array = []; @{$array} = ($x) x $n; return $array; }

Replies are listed 'Best First'.
Re^2: Applying an array to a function
by ikegami (Patriarch) on May 31, 2010 at 03:19 UTC
    Since you were trying to simplify the code, it should be noted that
    my $array = []; @{$array} = ($x) x $n; return $array;
    is a complicated way of writing
    my @array = ($x) x $n; return \@array;
    or
    my $array = [ ($x) x $n ]; return $array;
    or
    return [ ($x) x $n ];
      I use haskell a lot lately and it is nice to see that your last version is very close to how you can implement repeat into haskell:
      repeat a = [a,a..]
      Perl can be a really concise language. It astonish me time after time. I am really looking forward to perl6. (In haskell it is an infinite list, how is this in perl6?)
      I got the answer already. Perl6 is also lazy evaluated, so infinite lists are supported.