[EMAIL PROTECTED] wrote:
I'm reading the book Programming the Perl DBI to start work with
databases.  The DBI portion I'm getting OK, but I find the reference
here to @$ confusing. (This code is based from the book.)

my $sth1 = $dbh->prepare("select 'SCM_ORDERS_OUT', message_index,
message_no, message_event, time_stamp, data from log");

$sth1->execute();

my @stash;

while ($array_ref = $sth1->fetchrow_arrayref) {
  push @stash, [ @$array_ref ];  ##copy array contents
}

###dump stash contents
foreach $array_ref ( @stash ) {
   print "Row: @$array_ref\n";
}

The rows print out fine, so it "works", but I don't understand how.  I
need to be able to work with specific items in the output, such as the
column "data".  How would I reference it, using this example?

The term '@$' is a de-reference of a reference.

To be exact, $array_ref holds a reference to an array.  To access the array you 
need to de-reference it.  There are two ways to doing it.  The following are 
equivalent.

 @$array_ref
 @{ $array_ref }

You can use these anywhere you use an array:

 push @$array_ref, $some_data;
 if( grep { /$pattern/ } @{ $array_ref } ){
   ...
 }


--
Just my 0.00000002 million dollars worth,
 Shawn

"For the things we have to learn before we can do them, we learn by doing them."
 Aristotle

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to