Capturing Sybase SP output in Shell Script

Greetings,

I need to capture the output of a Sybase stored procedure, inside my
shell script( k shell). Based on this output, I need to call another
perl script, with input arguments as the result set of the procedure
execution. I need to keep looping through and call the perl script,
till the end of the Sybase stored procedure result set.

I am not sure, how do I capture the result set of the procedure and
use it while calling the perl file. Could someone please help.
A sample script/code snippet would help a lot.

TIA.

When I've needed to do something like this I've usually dome something like:

#get DB user password
stty -echo
trap "stty echo ; echo 'Interrupted' ; exit 1" 1 2 3 15
/usr/bin/echo "Enter password for userfoo account on barbar DB: "
read password
stty echo

#grab output and dump to temp file
isql -S Blah -U foo -P${password} -w 200 <<EOF > /tmp/tmp.$$ 2>&1
random sql query
and so on..
go
EOF

#check for errors/valid output and parse nicely or give error.
grep affected /tmp/tmp.$$ > /dev/null
if [ $? -eq 0 ]
then 
  Do whatever I'm going to do with my output
else
  cat /tmp/tmp.$$
fi

rm /tmp/tmp.$$

HTH

I tried this one out, but somehow still getting stuck. Probably, I should explain my problem once again in detail-

I have a shell script (ksh), which needs to run sybase quieries. Based on the o/p,
I need to call another perl program. I am not sure, how do I capture the output of the
sybase query, as it would be split into number of rows(not fixed, based on WHERE clause)
I was just working on a sample script. It looks like-

#!/bin/ksh
. /usr/local/ccms/pgl/cfg/pgl.env
echo ${SERVER} ${USER}
VAR=`isql -S${SERVER} -U${USER} -P${PASSWD} <<ENDOFTEXT
set nocount on
set rowcount 5
select UserId as 'Id' from tempdb..test_user
go
quit
ENDOFTEXT `
echo $VAR
#echo "values "
#echo $VAR | awk -F" " '{print $2}'
#col_look="this is test"
#I tried this one too...
IFS=' '
set -A bar $VAR
echo ${#VAR[@]}
echo ${bar[0]}
echo ${bar[1]}
echo ${bar[2]}
echo ${bar[3]}
echo "I am finished "
For example, the query returns,
id
---
1
2
3
4
5

I tried redirecting it to a temp file also, but no luck. May b I am doing smthg wrong,...
I need to use each of these values i.e. 1,2,3 etc as an input parameter to another program.
Hence, need to capture them into variables.
As no. of rows(hence these variables) is not fixed, also,
the o./p is in different rows, I am finding it difficult to capture them.
Appreciate your help.