package in enclosed block

N

newtan

Hello,

What's the advantage of having a "helper" package declaration enclosed
in a block?

file My/Gardener.pm

{
package My::Helper;
. . .
}

package My::Gardner;

use My::Helper;

.. . .

vs no enclosed block

file My/Gardener.pm

package My::Helper;
.....

package My::Gardener;
use My::Helper;

......

Thanks
 
A

Anno Siegel

Hello,

What's the advantage of having a "helper" package declaration enclosed
in a block?

file My/Gardener.pm

{
package My::Helper;
. . .
}

package My::Gardner;

use My::Helper;

. . .

vs no enclosed block

file My/Gardener.pm

package My::Helper;
....

package My::Gardener;
use My::Helper;

With the code shown there is no advantage. Why do you ask?

Anno
 
T

tan.dalat

Anno said:
With the code shown there is no advantage. Why do you ask?

I was just curious as I've seen code as described. Thanks for the
google reply tip otherwise, I'd be ripped apart by the posting cops :).
 
A

Anno Siegel

I was just curious as I've seen code as described.

Sure, it is done quite frequently. I can think of three reasons:

- You want a scope for lexical variables

- You want to fall back to the package the was in force before
the block

- You want the package code run at compile time, so need a BEGIN
block around it.

None of these apply to the code shown.

Anno
 
B

Brian McCauley

Anno said:
Sure, it is done quite frequently. I can think of three reasons:

- You want a scope for lexical variables

Or for lexically scoped declarations of package variables (using
our()).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,183
Messages
2,570,969
Members
47,524
Latest member
ecomwebdesign

Latest Threads

Top