Core Function Walk

From Sputnik Wiki
Jump to: navigation, search
Walk( <array>, <function> )

Contents

Description

Walk through the arrays items and execute a user defined function on each one.

Parameters

array

The array to use.

function

A user defined function literal or variable containing one.

Return Value

Success - Returns true.

Failure - Returns false.

Remarks

None.

Example

my $myarray = array(10, 20, 30, 40, 50, 60, 70);
$ret = Walk($myarray, function($value){++$value;});
println("Walk returned: $ret");
printr($myarray);

Same as above

my $myarray = array(10, 20, 30, 40, 50, 60, 70);
 
my $func = function($value)
		{
			println("Got value $value adding to it now...");
			++$value;
		};
 
 
$ret = Walk($myarray, $func);
println("Walk returned: $ret");
printr($myarray);

Example of using both the $key and $value

my $myarray = array(10, 20, 30, 40, 50, 60, 70, "Test" => 80, "Foo" => 90);
my $func = function($key, $value)
		{
			println("Got Key '$key' Value '$value' adding to it now...");
			++$value;
		};
$ret = Walk($myarray, $func);
println("Walk returned: $ret");
printr($myarray);
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox