Jonathan Vanasco wrote:
> 
> I apologize for the stupidity of this in advance-- its just something
> that I thought of in relation to mod_perl after starting a discussion on
> perlmonks about use constant vs sub(){} ...
> 
> 
> does anyone know if there is a memory/other difference under mod_perl for
> 
>     sub a {
>         my     @items= qw| 1 2 3 |;
>         foreach my $a ( @items ) {}
>     }
> 
> vs
> 
>     my     @_b_items= qw| 1 2 3 |;
>     sub b {
>         foreach my $b ( @ _b_items ) {}
>     }

I would imagine the 2nd to be marginally faster. Perl doesn't have to
re-allocate memory for the array each time the sub is called, but it does have
to re-initialize it. As long as the array's contents are constant I'd go with
the 2nd example, although I'd slightly modify it so that you can still lexically
scope the array to that sub:

{
  my @items = qw| 1 2 3 |;
  sub b {
    foreach my $b (@items) { }
  }
}

-- 
Michael Peters
Developer
Plus Three, LP

Reply via email to