[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-WebCGI] Pushing Array Refs Revisited (with solution)




8/7/99, Randy M. Zeitman wrote:
 >Is this a bug or am I missing something? (very hopefully the latter...)
 >
 >Given:
 >@a = (1,2,3);
 >@b = (4,5,6);
 >push @refs, [@a];
 >push @refs, [@b];


I find it cleaner and more flexible (and more efficient) to use refs
exclusively, ie...

	$a = [ 1, 2, 3 ] ;
	$b = [ 4, 5, 6 ] ;
	$refs = [] ;
	push @$refs, $a ;
	push @$refs, $b ;

Then <scalar @$refs> tells you how many rows, and you get at values with a
uniform, readable syntax:

	$value = $refs->[$RowNum]->[$FieldNum] ;

The syntax changes very little in the case your 'rows' ( $a and $b ) are
hashes:

	$a = { x=>1, y=>2, z=>3 } ;
	$b = { x=>4, y=>5, z=>6 } ;
	$refs = [] ;
	push @$refs, $a ;
	push @$refs, $b ;

	$value = $refs->[$RowNum]->{y} ;

rkm


==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-webcgi-request@macperl.org