Hallo,
Why can't a function change a variable defined in the calling script?
[tt]
$scriptvar=2
function scopetest
{
"scopetest before $scriptvar"
$scriptvar=$scriptvar+1
"scopetest after $scriptvar"
}
"Before $scriptvar"
scopetest
"After $scriptvar"
[/tt]
Gives:
[tt]
Before 2
scopetest before 2
scopetest after 3
After 2
[/tt]
The results show that a copy of the variable was updated within the function, not the actual variable.
I would have expected
[tt]
Actual 3
[/tt]
Any ideas/explanation,
-Frink
Why can't a function change a variable defined in the calling script?
[tt]
$scriptvar=2
function scopetest
{
"scopetest before $scriptvar"
$scriptvar=$scriptvar+1
"scopetest after $scriptvar"
}
"Before $scriptvar"
scopetest
"After $scriptvar"
[/tt]
Gives:
[tt]
Before 2
scopetest before 2
scopetest after 3
After 2
[/tt]
The results show that a copy of the variable was updated within the function, not the actual variable.
I would have expected
[tt]
Actual 3
[/tt]
Any ideas/explanation,
-Frink