Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: $#{$array_ref} changes in loop

by Trizor (Pilgrim)
on Apr 18, 2007 at 02:59 UTC ( [id://610688]=note: print w/replies, xml ) Need Help??


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

This is an autovivication trap. Perl autovivifies (creates) missing elements of refrences for hash and array refs, so every time you get $eventscores->[$i]->[2] you'll at least get something, either your desired variable or undef. So if you overrun your array before you run out of data $rider_id will get set to undef and then the inner loop will become infinite because the autovivified undef's will of course be equal to undef.

While perl will handle most bounds checking for you this is one situation you have to do it yourself.

Log In?
Username:
Password:

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

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

    No recent polls found