thomc has asked for the wisdom of the Perl Monks concerning the following question:
This will go into an endless loop because the value of $#{$eventscores) changes when the value of $i is incremented beyond it (where it should end) Here is the key dilemma for me. If I assign# $eventscores is an arrayref to an array of arrayrefs. # everything works fine until the last while iteration while ( $i <= $#{$eventscores} ) { $rider_id = $eventscores->[$i]->[0]; while ( $eventscores->[$i]->[0] == $rider_id ){ push (@scores, $eventscores->[$i]->[2] ); $i++; } #...more code.. unrelated to loop }
then set up the loop as$array_count = $#{$eventscores}
it works. Why? Thankswhile ($i <= $array_count)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: $#{$array_ref} changes in loop
by Sidhekin (Priest) on Apr 18, 2007 at 03:04 UTC | |
|
Re: $#{$array_ref} changes in loop
by Trizor (Pilgrim) on Apr 18, 2007 at 02:59 UTC | |
|
Re: $#{$array_ref} changes in loop
by GrandFather (Saint) on Apr 18, 2007 at 03:16 UTC | |
|
Re: $#{$array_ref} changes in loop
by Moron (Curate) on Apr 18, 2007 at 13:57 UTC | |
|
Re: $#{$array_ref} changes in loop
by chakram88 (Pilgrim) on Apr 18, 2007 at 13:04 UTC | |
|
Re: $#{$array_ref} changes in loop
by Jenda (Abbot) on Apr 19, 2007 at 08:41 UTC |