Of course, this leads to the question of "Why are you changing the value of a constant?" Or, "Why are you using the same constant name twice?" I mean, either it's constant for the whole bleeping world or it's not!
If you find you absolutely must use the same constant name twice for different values, you kinda have two options:
- Use different modules. I highly recommend this option.
- Use array constants.
use constant FOO => [qw(a b c)];
use constant FIRST => (0);
use constant SECOND => (1);
print FOO->[FIRST], $/;
print FOO->[SECOND], $/;
Personally, the second is very ugly and prone to error. But, TMTOWTDI, I guess.
------ We are the carpenters and bricklayers of the Information Age. Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement. Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified. | [reply] [d/l] |
Thanks. I'll go look up how to make a module; I've never done that before.
The reason the constant changes is as such: I'm parsing several different types of files based on how I'm called. The data is in rows & columns with different column headers between the files. So, depending on which subroutine I'm in (based on how I'm called) the constant TIME (referring to the column number) can take on different values.
| [reply] |
There's a much better way to do that. Use hashes. That's the canonical way to associate a string (like a column name) with a number (like a column number). :-)
Of course, this isn't a reason not to learn modules. You should do that because it's the next step.
------ We are the carpenters and bricklayers of the Information Age. Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement. Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.
| [reply] |
What is the sense of a constant, if it has different values, depending on the place ?
perl -MHTTP::Daemon -MHTTP::Response -MLWP::Simple -e ' ; # The
$d = new HTTP::Daemon and fork and getprint $d->url and exit;#spider
($c = $d->accept())->get_request(); $c->send_response( new #in the
HTTP::Response(200,$_,$_,qq(Just another Perl hacker\n))); ' # web
| [reply] [d/l] |