Variable declaration - C vs script style



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

.



Relevant Pages

  • Re: Use of `my
    ... variables in my scripts ... There is a lot of declaring in main that should be more localized. ... for each file found gets collected so repeated collection of same path ... But there is more to scoping than subroutine and global scope. ...
    (perl.beginners)
  • Use of `my
    ... variables in my scripts ... With a script that searches out specific regex from files that may be ... There is a lot of declaring in main that should be more localized. ... I've declared `@SearchedDir' in main because I want to use it in ...
    (perl.beginners)
  • Re: question on avoiding abuse of global
    ... I have some constants defined in a php script say config.php. ... I want to use the variables there defined in other scripts. ... couple of questions regd that: ... Is there an alternative to including config.php and declaring the ...
    (comp.lang.php)
  • Re: difference between rb_define_singleton_method and rb_define_method
    ... convention. ... anything in writing that stated theconvention. ... When declaring a class or module name, ... Is this a wrapper for postgress? ...
    (comp.lang.ruby)
  • Re: Late Binding in C#
    ... Do you mean declaring a variable as System.__ComObject? ... __ComObject isn't a public type. ... > I am writing an C# program. ... includes calling the COM object's IDispatch interface. ...
    (microsoft.public.dotnet.languages.csharp)