nagalenoj has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
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.
pq.pmpl filepackage pq; use strict; use warnings; use constant { ONE => "1" }; sub new { my ($class) = @_; bless {}, $class; } sub pr { print main::FO1; } 1;
use strict; use warnings; use pq; use constant { FO1 => "value" }; print pq::ONE; # Prints 1, working right.! my $obj = new pq; pq->pr(); # says 'print() on unopened filehandle FO1 at pq.pm l +ine 28.'
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Accessing main::Constant
by BrowserUk (Patriarch) on Dec 16, 2009 at 05:32 UTC | |
by nagalenoj (Friar) on Dec 16, 2009 at 05:52 UTC | |
by BrowserUk (Patriarch) on Dec 16, 2009 at 06:07 UTC | |
by Anonymous Monk on Dec 17, 2009 at 08:01 UTC | |
by desemondo (Hermit) on Dec 17, 2009 at 08:49 UTC | |
| |
by ikegami (Patriarch) on Dec 17, 2009 at 16:03 UTC | |
Re: Accessing main::Constant
by biohisham (Priest) on Dec 16, 2009 at 08:07 UTC | |
Re: Accessing main::Constant
by bart (Canon) on Dec 17, 2009 at 09:02 UTC | |
Re: Accessing main::Constant
by ikegami (Patriarch) on Dec 17, 2009 at 16:02 UTC |
Back to
Seekers of Perl Wisdom