Basically i am trying to figure out when a function is called, and then exited, what sticks around for subsequent calls, and what is destroyed and needs to be recreated internally on each call.
I'm assuming that @list is not going to ever change in blah().# case 1 sub blah { ... my @list = qw(# list of things); foreach my $item (@list) { ... } # case 2 { my @list; BEGIN { @list = qw(# list of things); } sub blah { ... foreach my $item (@list) { ... } } # case 3 sub blah { ... foreach my $item qw(# list of things) { ... }
In case 1, im pretty sure that @list is re-initialized on each call to blah()
In case 2, @list is initialized once, in the BEGIN{}, and never goes away, because of the closure.
case 3, i am not sure what happens. Does the inline list re-create itself on each call to blah(), or is it created once and sticks around somewhere? I'm uncertain about this one because the list is never assigned to a variable (as a whole), which makes me think that its sticking around somewhere.
I could ask similar questions about inlined regexs, etc.
UPDATE:
changed my blah {} to sub blah {} - as it should be.
In reply to Resource allocation question by shemp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |