Welcome to the Monastery | |
PerlMonks |
Re: compare arrays numbersby ikegami (Patriarch) |
on Feb 16, 2010 at 18:52 UTC ( [id://823529]=note: print w/replies, xml ) | Need Help?? |
To do something to each element of an array, you need a loop over each element of the array. I don't know what's special about for loops that they need to be avoided. Maybe if you told us that, we could help you better. I wouldn't use a for loop anyway. I'd use a counting loop. The syntax of a counting loop is much simpler than that of a for loop, it's faster do to the much smaller number of opcodes, and it also uses a constant amount of memory. (Mostly for the first reason. The other two are bonuses.) Counting loop (an optimised form of foreach loop):
Foreach loop:
Using map like a foreach loop: while loop:
Goto loop:
Recursion loop:
Recursion loop, take 2:
pairwise loop:
Update: Added more alternatives :)
In Section
Seekers of Perl Wisdom
|
|