M
markoa
Hello,
I've been wondering whether there are any differences in performance
when declaring variables within loops
comparing to all forward declarations. I'm mostly writing up to a few
hundred lines long scripts, but I need
relatively a lot variables, which look kind of ugly and IMO make the
script less readable when declared all
at the top. For example,
my ($var1, var2, var3, var4, var5, ...);
my (another set of variables);
while (...) {
$var1 = ...
$var2 = &foo($var1);
...
if ($var3) {
...
}
for ($var4 : ...)
}
vs
while (...) {
my $var1 = ...
my $var2 = &foo($var1);
...
my $var3 = ....;
if ($var3) {
...
}
for (my $var4 : ...)
}
Will the latter approach lead to more memory allocation and/or
significantly more work
for the garbage collector?
Marko
I've been wondering whether there are any differences in performance
when declaring variables within loops
comparing to all forward declarations. I'm mostly writing up to a few
hundred lines long scripts, but I need
relatively a lot variables, which look kind of ugly and IMO make the
script less readable when declared all
at the top. For example,
my ($var1, var2, var3, var4, var5, ...);
my (another set of variables);
while (...) {
$var1 = ...
$var2 = &foo($var1);
...
if ($var3) {
...
}
for ($var4 : ...)
}
vs
while (...) {
my $var1 = ...
my $var2 = &foo($var1);
...
my $var3 = ....;
if ($var3) {
...
}
for (my $var4 : ...)
}
Will the latter approach lead to more memory allocation and/or
significantly more work
for the garbage collector?
Marko