Your variables (scalars and arrays in this case) which are declared outside the loop will continue to hold their values once the loop is finished - just like they do in your second example. Try it and see!
Scoping is an important topic in programming generally, not just in Perl. It will be worth your time to read and learn more about it. The usual reference given is Coping with scoping which covers lots more than you will need for this particular question - but it is all good stuff.
🦛
In reply to Re^3: How can I get the last element of an array inside of fetchall_arrayref?
by hippo
in thread How can I get the last element of an array inside of fetchall_arrayref?
by Lewisa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |