The package declarations themselves are not too exciting since, as you can see below, the package can be referenced in other packages. However, notice for a variable declared with our it doesn't matter whether you put the package-in-the-block before or after the normal one, the use of the unqualified variable will default to the one outside of the block.

#!/usr/bin/perl -w use strict; { package niceThing; our $compat = 4234; sub howdy { return qq|Howdy in package niceThing!|; } } package nonNiceThing; our $compat = 4555; sub howdy { return qq|Howdy in package nonNiceThing!|; } package main; print niceThing::howdy(); print nonNiceThing::howdy(); print "\n$compat\n"; print "\n$niceThing::compat\n";
Result:
Howdy in package niceThing!Howdy in package nonNiceThing! 4555 4234

This works even if you take the package name out of the enclosed block so my suspicion is that in the code you are looking at the package declaration was put into the block for convenience and readability.

Celebrate Intellectual Diversity


In reply to Re: Package declaration in code block by InfiniteSilence
in thread Package declaration in code block by McA

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.