PEPPLER.ORG
Michael Peppler
Sybase Consulting
Menu
Home
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
Freeware
Sybperl
Sybase::Simple
DBD::Sybase
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
FAQs
Sybase on Linux FAQ
Sybperl FAQ
Personal
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: "Pablo Sanchez" <pablo at mew dot corp dot sgi dot com>
Subject: Re: Help! Alternate syntax for a foreach() loop
Date: Mar 6 1996 2:39AM

On Mar 5,  1:55pm, Michael Sattler wrote:
> Subject: Help! Alternate syntax for a foreach() loop
> Michael's Sybperl examples provide something like this:
>
> >$ref = $d->sql("select * from foobar_table");
> >
> >foreach $line (@$ref) { print "@$line\n"; }
>
> Well, what if I want to reference the nth element instead of iterating
> through all the results?  I forget the syntax.
>
> Swift kicks gratefully accepted.
>

I didn't get the above to work as advertised but I'm a newbie to
PERL...  instead what I did was:

@ref = $d ...

so then it's easy to do what you want:

N=8;
($col1, $col2, $col3 ) = split('~', @ref[N]);

-- 
Pablo Sanchez              | Ph # (415) 933.3812        Fax # (415) 933.2821
pablo@sgi.com              | Pg # (800) 930.5635  -or-  pablo_p@corp.sgi.com
===============================================================================
I am accountable for my actions.   http://reality.sgi.com/pablo [ /Sybase_FAQ ]