2009-07-07 2 views

Antwort

23

Hier ist ein Beispiel dafür, wie dies zu tun, um den Anruf (&) Operator.

# define 3 functions 
function a { "a" } 
function b { "b" } 
function c { "c" } 

# create array of 3 functioninfo objects 
$list = @(
    (gi function:a), 
    (gi function:b), 
    (gi function:c) 
) 

0, 1, 2 | foreach { 
    # call functions at index 0, 1 and 2 
    & $list[$_] 
} 

-Oisin

P. S. dies bedeutet, dass Ihre Pipeline bve um so etwas wie geändert sollte: ist

$Fields[$i] = $Fields[$i] | & $FunctionTable[$i] 
+0

Sehr cool. Danke vielmals! – tellingmachine

2

Hier etwas ähnliches auch den & Operator:

 
function f1 
{ "Exec f1" } 

function f2 
{ "Exec f2" } 

function f3 
{ "Exec f3" } 

function f4 
{ "Exec f4" } 

function UseFunctionList ([string[]]$FunctionList) 
{ 
foreach ($functionName in $functionList) 
    { 
    & $FunctionName 
    } 
} 

function Go 
{ 
'List 1' 
$FunctionList = 'f1','f2','f3','f4' 
UseFunctionList $FunctionList 
'List 2' 
$FunctionList = 'f4','f3','f2' 
UseFunctionList $FunctionList 
}