Clovis_Sangrail has asked for the wisdom of the Perl Monks concerning the following question:
I am going thru the Alpaca book, currently trying out the examples of objects/instances. The packages (or classes) defined in the text are typically written as:
{ package somename; #perlcode }
I'm used to seeing things analagous to the 'package' keyword (ex 'sub') outside of the block of code. I find that Perl (or my example programs, at any rate) run identically with the syntax of the packages written as above (from the textbook) or in any of the following ways:
package somename; { #perlcode } package somename { #perlcode } package somename { #perlcode }; { package somename; #perlcode };
I do get syntax errors with the following:
{ package somename #perlcode }
When the package keyword is inside the block it seems you have to have a semicolon after the package/class name. But I am surprised that so many other variations all work. My question is, am I introducing some kind of subtle difference in scope or something like that? Are they really all the same?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: OO Perl Baby Steps
by davido (Cardinal) on Jun 12, 2013 at 15:39 UTC | |
|
Re: OO Perl Baby Steps
by cdarke (Prior) on Jun 12, 2013 at 15:27 UTC | |
|
Re: OO Perl Baby Steps
by choroba (Cardinal) on Jun 12, 2013 at 15:45 UTC | |
|
Re: OO Perl Baby Steps
by Clovis_Sangrail (Beadle) on Jun 14, 2013 at 16:45 UTC | |
by jeffa (Bishop) on Jun 14, 2013 at 16:57 UTC | |
by Clovis_Sangrail (Beadle) on Jun 19, 2013 at 17:14 UTC | |
by tobyink (Canon) on Jun 20, 2013 at 11:46 UTC | |
by jeffa (Bishop) on Jun 19, 2013 at 17:24 UTC | |
by Anneq (Vicar) on Jun 22, 2013 at 16:58 UTC | |
|