See argument @ Bash FAQ entry #24: “I set variables in a loop. Why do they suddenly disappear after the loop terminates? Or, why can’t I pipe data to read?” (most recently archived here).
Summary:
This is only supported from bash 4.2 and up.
You need to use different ways like command substitutions instead of a pipe if you are using bash.