develooper Front page | perl.beginners | Postings from May 2007

Array of Array refs

Thread Next
From:
Brian
Date:
May 28, 2007 03:36
Subject:
Array of Array refs
Message ID:
1180324847.364219.70910@r19g2000prf.googlegroups.com
Hi All-
  I am trudging through some DBI, XML, etc.. I had a problem and was
baffled by how to get at array elements out of a series of pushed
array refs. But, by simplifying the problem, I found that the syntax I
used was in error. here is the small sample, already debugged. Hope
this helps someone...

#!/usr/bin/perl

	my @tRespsA;

	my @fieldList = ( "one", "two", "three", "four" );
	my @r1 = ( 1, 2, 3, 4 );
	my @r2 = ( 13, 14, 15, 16 );
	my @r3 = ( 23, 24, 25, 26 );

	push @tRespsA, \@r1;
	push @tRespsA, \@r2;
	push @tRespsA, \@r3;

	foreach my $tRowRef ( @tRespsA ) {
		my $tCnt=0;
		foreach my $tFld (@fieldList) {
			#if ( $tRowRef->[ $tCnt] eq "") { next; }
			print $tFld . "='" . $tRowRef->[ $tCnt++ ] . "' \r";
		}
	}


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About