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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

moving through loop

Status
Not open for further replies.

eatr

Technical User
Jan 20, 2006
48
I want to be able to move through the columns of a dynamic (size varies --nothing constant) 2 dimensional array, making calculations and then changes to the values. The colums would be accessed as pairs.

for example

0 1 2 3 4 5 6 7 ...

a 123 000 ......................

b 456 001 ......................

c 789 012 .......................


In pairs, I want to work first with 1,3, then 2,4 etc.

I've tried embedding foreach loops:

for my $l (1,3) {

for my $m (2,4) {

....

but can't get it to work

suggestions please





 
arrays start at 0 (zero) not 1 (one). But I don't understand your question.

- Kevin, perl coder unexceptional! [wiggle]
 
I realize that, that's why I've started with '0' in the heading.

Here's what I want, more specifically:

to loop through the array comparing 2 columns concurrently

if I wanted to work with columns 1,3 first run through

then columns 2,4 2nd run through, etc.

how would I write the for loop

(there will be embedded fors, whiles, and ifs within)

thanks

hope this a bit clearer



 
generic example:

Code:
my @array = ([1..10],[1..10],[1..10]);
foreach my $line (@array) {
   for my $i (1 .. $#{$line}-1) {
      print "'$line->[$i],$line->[$i+1]'";
   }
   print "\n";
}





- Kevin, perl coder unexceptional! [wiggle]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top