Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: OO Perl Baby Steps

by davido (Archbishop)
on Jun 12, 2013 at 15:39 UTC ( #1038504=note: print w/ replies, xml ) Need Help??


in reply to OO Perl Baby Steps

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


Comment on Re: OO Perl Baby Steps
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (5)
As of 2014-12-27 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (177 votes), past polls