[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Passing variables by reference conflicts with local
From: |
Marc Herbert |
Subject: |
Re: Passing variables by reference conflicts with local |
Date: |
Tue, 04 May 2010 10:11:31 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100330 Fedora/3.0.4-1.fc12 Thunderbird/3.0.4 |
Le 01/05/2010 09:18, Freddy Vulto a écrit :
> I would like to call t(), and let it return me a filled variable by
> reference, that is without polluting the global environment.
I'd like to know why you absolutely want the callee to perform a
side-effect on the caller. This is your original sin
IMHO. Side-effects are evil, use as little of them as you can. Here is
a more functional approach:
blackbox() {
local a
printf '%s\n' "$1=bar1"
printf '%s\n' "$2=bar2"
}
f() {
local b c
# This eval is safe because we trust our own, simple blackbox
# function
eval $(blackbox b c)
echo $b; echo $c
}
Of course whenever "blackbox" returns only one value the whole thing
can be much simpler, just: b=$(blackbox)
Re: Passing variables by reference conflicts with local, Greg Wooledge, 2010/05/03
Re: Passing variables by reference conflicts with local,
Marc Herbert <=