in reply to Re: Re: Behavior of compile-time constants?
in thread Behavior of compile-time constants?

That's just it: you shouldn't have to fix the context. Knowing you have to fix the context means knowing how the constant pragma is implemented, and that's not something you should need to know.
  • Comment on Re: Re: Re: Behavior of compile-time constants?

Replies are listed 'Best First'.
Re: Behavior of compile-time constants?
by Abigail-II (Bishop) on Jun 14, 2002 at 18:19 UTC
    No, all you need to know is how => works. You have the same problem in:
    #!/usr/bin/perl use strict; use warnings 'all'; sub foo { my %hash = (shift => 1); print keys %hash, "\n"; } foo "bar"; __END__
    That prints shift and not bar.

    Abigail

      My recommendation to him was to use variables for his constants. (Yes, I know that sentence sounds bizarre.) Variables certainly behave differently in different contexts, but people are not as likely to make mistakes with them because they know they've got a variable rather than some mysterious constant thing.
        Let's go crazy and use the worst of both worlds:
        #!/usr/bin/perl use strict; use warnings 'all'; use variable i => 0; use variable array => []; array = [2, 4, 5, 8]; for (i = 0; i < 4; i ++) { print array -> [i], "\n"; } __END__ 2 4 5 8

        Abigail