bash pip-isms or right hand side of pipe variables

Unlike my default shell (zsh), bash has a wonderful feature where it doesn’t keep variables that are set at the other end of a pipe, so for example:
cat foo | while read bar; do
echo $i

Yields an empty line. I’ve been stung once or twice on this as I prototype the code initially in an interactive shell, which doesn’t exhibit the issue.
The simplest solution is to use a named pipe.

mkfifo /tmp/foo$$
cat foo >/tmp/foo$$&
while read bar; do
done </tmp/foo$$

This gives the last line of the file in the i variable.