There's more than one way to do things | |
PerlMonks |
Re^3: How can I get the last element of an array inside of fetchall_arrayref?by hippo (Bishop) |
on Mar 23, 2021 at 18:45 UTC ( [id://11130229]=note: print w/replies, xml ) | Need Help?? |
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 Section
Seekers of Perl Wisdom
|
|