in reply to Re^2: How to access outside variable
in thread How to access outside variable

You still can't access the outer value without putting the variables in separate packages and declaring the outer one with our. The second inner my declaration "hides" the first outer my declaration. If you want to access two variables with the same name, you have to give them separate packages, even if it all happens in a single .pl file.

Packages aren't necessarily modules. You can have many package declarations in a single file and many files sharing the same package declaration. Packages are just namespaces you can use to group together variables and scope them logically rather than via text position (inside/outside curly braces).

If you really, really don't want to use packages to scope your variables, then you will have to give your inner and outer variables different names. Is there a particular reason you aren't doing that already?

Replies are listed 'Best First'.
Re^4: How to access outside variable
by Anonymous Monk on Jan 21, 2011 at 06:10 UTC

    Thanks for giving good explanation.

    This question asked in my interview panel.