Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Your usages have subtly different semantic, and in some cases, practical meanings, especially if you're using Perl 5.14 or newer.

{ package somename; ..... }: This creates a lexical scope, and inside that lexical scope you happen to be working with package somename. When the block ends, you will be working back in the previous package again, though this is not the preferred syntax (see below) as of Perl 5.14.

package somename; { ..... }: This declares that you're working with package somename, and then creates a lexical scope. The two are not really related to each other, but it does happen that this lexical scope was created while you're working in package somename.

package somename { ..... }: This is a new Perl 5.14 feature; you've declared that you'll be using package somename for the duration of the following block (I suppose you could change within the block, but haven't tried). Once the block expires, the package you will find yourself working within will revert back to whatever was in effect before this package block.(See http://www.perl.com/pub/2011/05/new-features-of-perl-514-package-block.html).

The next two are just the same as other constructs you demonstrated, but with an extra semicolon at the end, which has no effect. You can put a semicolon just about anywhere you want as long as it doesn't break a statement. print "hello world\n" ;;;;;;;;;;;;; print "Hello again\n";;;;;; # Perfectly legal

The last one is a syntax error because you didn't separate the "package somename" statement from the next statement with a semicolon. It's not a syntax error if that statement is the last statement within the block, since semicolons are optional for the final statement in a block.


Dave


In reply to Re: OO Perl Baby Steps by davido
in thread OO Perl Baby Steps by Clovis_Sangrail

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!
  • 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, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others musing on the Monastery: (5)
    As of 2014-09-21 21:45 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (176 votes), past polls