View Single Post
Old 01-22-2013, 10:06 AM   #101
knc1
Going Viral
knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.knc1 ought to be getting tired of karma fortunes by now.
 
knc1's Avatar
 
Posts: 17,212
Karma: 18210809
Join Date: Feb 2012
Location: Central Texas
Device: No K1, PW2, KV, KOA
Quote:
Originally Posted by stepk View Post
I didn't explain myself exactly. json_parse calls a user-provided function - make_label in this case. I want for the user-provided function to get an unmodified IFS. So I need to reset IFS before calling the user's function from within json_parse, don't I?
Code:
json_parse() {
local IFS0=$IFS IFS ... foo=$2
...
IFS=,
...
IFS=$IFS0
$foo
...
}
or is the local scoping not affecting called subs?
Also is it safe to save $IFS and declare it local in a single statement, or should I break it into two lines
Code:
local IFS0=$IFS
local IFS ...
thanks
Yes, you want that - since you shouldn't guess a what an external function might expect.

I really must run (car keys in hand) - but . . . .
Here is a (somewhat large) example (in BASH!) of the handling of a lot of those issues:
http://hg.minimodding.com/repos/cats/shacat.hg/

In particular the topmost defines for the IFS strings.
That way a reader will get a clue as to what is happening at each step along the way.
knc1 is offline   Reply With Quote