If I uncomment this line it won't compile because it claims MY_CONSTANT3 is a bareword and not a constant.
Correct. At compile time, there is no function named MY_CONSTANT3, so MY_CONSTANT3 is treated as a string literal. This is obviously not what you want, so strict lets you know.
You need to execute require "constants.pl"; before my $var = MY_CONSTANT3; is compiled.
Since using require to load something that doesn't have a package makes no sense, I'll fix that at the same time.
#!/usr/bin/perl
use strict;
BEGIN {
do "constants.pl";
die $@ if $@;
}
my $var = MY_CONSTANT3;
print "$var\n";
By the way, I removed the exit 1; since there's no reason to signal an error occured.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.