in reply to Re^2: What is method () ?
in thread What is method () ?

I don't know the context that TheDamian wrote that in, but I would consider it to be misleading as posted here.

When you have a single package declared in a file there is no need for the braces. The file is a single enclosing lexical scope so the braces are unnecessary, and even possibly confusing.

OTOH, when you have a mutliple packages declared in a file then you should use the braces as it enforces lexical seperation between the package implementations. But the thing is you probably should put the package declaration inside of the braces and not outside.

But that leads to the question of why you would put mutliple packages in a single file. I know of a few reasons to do so, but IME its rare that they come up.

---
$world=~s/war/peace/g

Replies are listed 'Best First'.
Re^4: What is method () ?
by Perl Mouse (Chaplain) on Oct 06, 2005 at 08:31 UTC
    Most of the time when I put multiple package statements in the same file, I do that to show a specific behaviour. To explain something, or to show a bug. Like a posting to Perlmonks or usenet. Or on a mailinglist. ;-)
    Perl --((8:>*

      Well, my response was more motivated by the comment "yeah but Perl Best Practices says you should do it".

      So why does Perl Best Practices say it? I don't know. As I said I don't have the context to see exactly what TheDamian was saying. Basically I dont think it is "best practice" to do this. It is a good idea when multiple packages are in a single file, but its of minimal value when you only have one, and in that case IMO is actually bad practice as it increases indentation with no benefit.

      My guess based on the quoted text is that TheDamian meant the case of multiple packages in one file and not a general advisory. Which just says that taking PBP quotes out of context isn't so wise.

      ---
      $world=~s/war/peace/g