in reply to Scope Between global and my

You can create your own lexical scope by placing braces around the subroutines you want to access the variable.

{ my $data; sub foo { ... } sub bar { ... } }

Alternatively, if these subroutines are related so closely, you might want to just create a separate package for them and use a package-global variable:

package Foo; our $data; sub foo { ... } sub bar { ... } 1;

Replies are listed 'Best First'.
Re: Re: Scope Between global and my
by ctilmes (Vicar) on Apr 01, 2004 at 18:53 UTC
    I would only use the package-global variable if other packages (or main) must have access.

    In this case, just use a 'package' lexical:

    package Foo; my $data; sub foo { ... } sub bar { ... } 1;