long answer:
Variable Scoping in Perl: the basics
short answer:
- forget about 'our' and 'local' (for now)
- identify the relevant blocks (= something enclosed in '{ }')
- if you need the variable outside of the block, define it outside
minimalistic example to set a value inside a conditional / loop / block:
(I intentionally used the variable '$value' inside the block to demonstrate 'my'. It is not mandatory, you can also assign directly.)
my $variable;
if (1 == 1) {
my $value = 'a';
$variable = $value;
}
else {
my $value = 'b';
$variable = $value;
}
# => '$variable' now contains 'a'