Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Re: Accessing main::Constant

by biohisham (Priest)
on Dec 16, 2009 at 08:07 UTC ( #812991=note: print w/replies, xml ) Need Help??

in reply to Accessing main::Constant

First things first, accessing a class component in a fashion similar to "print pq::ONE" doesn't quite express OOP as it should, the idea of classes in OOP is to provide for encapsulation of data and methods into objects and that these objects interface the class data and methods they are instances of.

In your code, "my $obj = new pq;" brings an object into existence but to no avail since you've not used it... You declared a constant in the main package, since you wanted to access that constant with a class package and since that class has an object, use the object instead to call/invoke the class method through which you wanted to access that constant in main,

use strict; use warnings; use pq; use constant { FO1 => "value" }; my $obj = new pq; #accessing a class through an object... print $obj->ONE; $obj->pr;
OOP is about hiding data and routines away from the rest of the program to simplify the code and enhnace privacy..

Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://812991]
[choroba]: just one of its angles, in fact
[LanX]: <|--
[choroba]: Reminds me of an old joke about an orchestra...
erix imagines that in a true Lancs accent
[choroba]: so a Czech orchestra rehearses a new piece by a German composer
LanX LOL of the day ... the Turkish Anonymous Alcoholics stopped their "No to alcohol" campaign for political reasons ...
LanX omg my browser is posting again on its own ...
[LanX]: choroba: GREAT JOKE! xD

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2017-03-27 11:46 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (319 votes). Check out past polls.