Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: $#{$array_ref} changes in loop

by Sidhekin (Priest)
on Apr 18, 2007 at 03:04 UTC ( [id://610689]=note: print w/replies, xml ) Need Help??


in reply to $#{$array_ref} changes in loop

You are bitten by autovivification:

while ( $eventscores->[$i]->[0] == $rider_id ){

If $i at this time points beyond the end of the array, an arrayref will spring into existence, as you dereference the hitherto unexisting element.

Solution: Don't do that. A common strategy is to protect the dereferencing:

while ( $eventscores->[$i] and $eventscores->[$i]->[0] == $rider_id ){

Depending on the rest of your outer loop, other solutions may be cleaner though.

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://610689]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-25 21:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found