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.'
In reply to Accessing main::Constant by nagalenoj
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |