Here's another "What's a quick and real neat way of...." type question

Shaun McCarthy shaunm at web.co.nz
Thu Nov 14 15:32:03 CST 2002


Good point - you can get around the 0, '0', '' with undef(my($a, $b) = (shift @a, shift @b))[0]) but yeah having an undef in an array will be bad...
 
In which case I think:
 
while (@a && my($a, $b) = (shift @a, shift @b)) {
}
 
is prolly slightly better as it is easier to read than
 
while(my($a, $b) = (@a ? (shift @a, shift @b) : ()) ){
}
 
And to get rid of the equal length assumption:
 
while (@a && @b && my($a, $b) = (shift @a, shift @b)) {
}
 
which will end as soon as one of the arrays is finished...
 
Shaun 

	-----Original Message----- 
	From: Grant McLean 
	Sent: Fri 15/11/2002 8:07 a.m. 
	To: Shaun McCarthy; Piers Harding; Enkidu 
	Cc: wellington-pm-list at pm.org 
	Subject: RE: Here's another "What's a quick and real neat way of...." type question
	
	

	Shaun McCarthy wrote:
	> so if you go: (my($a, $b) = (shift @a, shift @b))[0] you
	> will get the value assigned to a, which will be undef when
	> they arrays runs out (assuming the same length thing), which
	> equates to false.
	
	Which could be quite a cool trick assuming the arrays could
	never contain undef, or 0, or '0', or ''.
	
	Grant
	
	===============================================================
	Grant McLean        BearingPoint Inc - formerly The Web Limited
	+64 4 495 9026           Level 6, 20 Customhouse Quay, Box 1195
	gmclean at bearingpoint.biz                Wellington, New Zealand
	




More information about the Wellington-pm mailing list