Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping through an array with empty cells

Status
Not open for further replies.

jamsman

Technical User
Jul 22, 2005
38
DE
i need to loop through an array and print the content (plus other things) the array contains empty cells e.g. if i try to use the while(@array) loop i stops when it gets an empty cell any ideas

thanks
 
you realy shouldn't use while with an array, use "for" or "foreach".
 
Kevin is right, you don't really want to use a while loop to iterate over an array. Try something like:
Code:
my @array = ('a', 'b', undef, 'c');
foreach (@array) {
    defined() ? print : next;
}
 
rhash,
Just teasing you here a little! ;-)
Code:
my @array = ('a', 'b', undef, 'c');
defined && print foreach (@array);


Trojan.
 
Trojan - nothing wrong with a little teasing here and there, but there is a little method to my maddness. (-:
jamsman said:
i need to loop through an array and print the content (plus other things)
The syntax you posted makes it hard to do the 'other things'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top