in reply to Using constants. What am I doing wrong?

Hello,
A "use" statment is called at compile time, before any other code is evaluated. So when your constant is looking for $Base and it is not yet initialized. It might work if you put the $Base in a BEGIN block before the "use".

rlb3
  • Comment on Re: Using constants. What am I doing wrong?

Replies are listed 'Best First'.
Re^2: Using constants. What am I doing wrong?
by Random_Walk (Prior) on Feb 22, 2005 at 11:20 UTC

    update

    I am dumb, the one below does not work 'cos I put a my in the BEGIN block, when good habits turn bad! Without the my it works a charm

    >perl -le'BEGIN{$BASE="are belong to us"} use constant BASE => $BASE; print "all your base ", BASE' all your base are belong to us >

    original message

    I though that would work too but it does not for me

    > perl -le'BEGIN{$BASE="are belong to us"} use constant BASE => $BASE; print "all your base ", BASE' all your base > # but this does >perl -le'use constant BASE=>"are belong to us"; print "all your base ", BASE' all your base are belong to us >
    But I guess the OP was after something more flexible

    Cheers,
    R.

    Pereant, qui ante nos nostra dixerunt!