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: Michael Peppler <mpeppler at MBAY dot NET>
Subject: Could someone explain this please
Date: Mar 5 1999 3:28PM

Andrew J Davies writes:
 > Hi
 > I know this works. But I'm unsure of the @$database.
 > Could anyone explain please.
 > Thanks for you time.
 > 
 > @databaselist = $dbh->ct_sql("select name  from sysdatabases where name in
 > ('master', 'sybsecurity', 'sybsystemprocs')");

In this case $dbh->ct_sql() returns an array of references to arrays.
The array is built like this:

while(@data = $dbh->ct_fetch) {
    push(@retval, [@data]);
}

The [] means a "reference" to an array. Saying [@data] means "make a
copy of the @data array, and take a reference to it". 

A "reference" is a scalar variable that points ("references") some
other object (another scalar, an array, a hash, a subroutine).

 > foreach $database (@databaselist)
 > {
 >      print "@$database\n";

Here $database is a reference to an array. You can verify that by
using 

	print ref($database), "\n";

You "de-reference" a reference by either

	prepending a symbol giving the type that we are referencing
	(so @$database refers to the entire array that $database
	references)

or by

	using the $ref-> notation (so $database->[0] refers to the
	first element of the array referenced by $database). This can
        also be written $$ref.

Hope this helps a little bit!

Michael
-- 
Michael Peppler         -||-  Data Migrations Inc.
mpeppler@mbay.net       -||-  http://www.mbay.net/~mpeppler
Int. Sybase User Group  -||-  http://www.isug.com
Sybase on Linux mailing list: ase-linux-list@isug.com