in reply to Applying an array to a function

This does the same thing?

#! perl -slw use strict; sub test { my $x = shift; my $y = shift; my $z = shift; print $x + $y + $z; } sub apply2 { my( $code, $argsRef ) = @_; return $code->( @$argsRef ); } apply2( \&test, [1,2,3] );

Replies are listed 'Best First'.
Re^2: Applying an array to a function
by eklerks (Novice) on Jun 02, 2010 at 14:02 UTC
    Ah yes, I was searching for something like that. I knew I didn't need the eval to achieve my goals. Eval is Evil. Most of the times. If I had took some time, I would have realised, that (pseudocode):
    @t = (1,2,3); test(@t) == test((1,2,3)) == test(1,2,3);
    So the apply function isn't needed either, I can just write (like your example):
    test(@{[1,2,3]});
    Thanks