Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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]
[Discipulus]: indeed Monopoli it's a real place marto

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2018-01-23 12:40 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (245 votes). Check out past polls.