<?xml version="1.0" encoding="windows-1252"?>
<node id="812972" title="Accessing main::Constant" created="2009-12-16 00:23:29" updated="2009-12-16 00:23:29">
<type id="115">
perlquestion</type>
<author id="711414">
nagalenoj</author>
<data>
<field name="doctext">
Dear monks,
&lt;p&gt;I've tried to print a constant which is declared in main package. But, it's printing error. I don't know where I made the mistake. The code is as follows.&lt;/p&gt;

&lt;i&gt;pq.pm&lt;/i&gt;
&lt;code&gt;
package pq;
use strict;
use warnings;

use constant {
    ONE =&gt; "1"
};

sub new {
    my ($class) = @_;

    bless {}, $class;
}

sub pr { print main::FO1; }
1;
&lt;/code&gt;

&lt;i&gt;pl file&lt;/i&gt;
&lt;code&gt;
use strict;
use warnings;
use pq;

use constant {
FO1 =&gt; "value"
};

print pq::ONE;   # Prints 1, working right.!

my $obj = new pq;
pq-&gt;pr();        # says 'print() on unopened filehandle FO1 at pq.pm line 28.'

&lt;/code&gt;</field>
</data>
</node>
