in reply to Error with using structs as subroutine parameters

With few exceptions lines like

use strict; use warnings; use Class::Struct;
should be listed at the beginning of a file, not inside of subroutines. I'm not sure, but use of a class inside a subroutine might lead to problems because the implied 'require' would create closures instead of sub-subroutines.

Replies are listed 'Best First'.
Re^2: Error with using structs as subroutine parameters
by JavaFan (Canon) on Jun 08, 2009 at 10:43 UTC
    should be listed at the beginning of a file, not inside of subroutines.
    Why? If you only need a module inside the subroutine, keeping the 'use' close to its usage means that if you later on remove the subroutine, you're not left 'using' a module that isn't actually used.
    I'm not sure, but use of a class inside a subroutine might lead to problems because the implied 'require' would create closures instead of sub-subroutines.
    Rubbish. It will not create closures, and Perl doesn't have any concept of "sub-subroutines" (what are they? Really tiny routines?)

      Ok, accepted. I thought this was the same situation as in mod_perl usage where you had to be careful with global variables because mod_perl put everything into its subroutine. I forgot that used modules usually have a package statement at the beginning that should solve the problem

      and Perl doesn't have any concept of "sub-subroutines"

      It is astonishing how easily one is misunderstood on the internet. Naturally perl has no concept of sub-subroutines and that is what I was saying