sathya_myl has asked for the wisdom of the Perl Monks concerning the following question:

Here is the code i used:

use strict; my $word64 = 1; use constant CRACKLIB => (($word64 == 1) ? "/usr/lib64/cracklib_dict" + : "/usr/lib/cracklib_dict") ; print CRACKLIB ;

which prints /usr/lib/cracklib_dict

Replies are listed 'Best First'.
Re: Unable to assign value to constants using ternary operator
by moritz (Cardinal) on May 11, 2012 at 10:07 UTC

      thanks for the reply moritz but i'm assigning the value of $word64 based on a condition.Here is the code:

      my $hw = `uname -i`; my $word64 = 1 if ( $hw =~/x86_64|ia32e/);

      Now how can i use constant for this one?

        Force that stuff to happen at compile time using BEGIN:

        my $word64; BEGIN { my $hw = `uname -i`; $word64 = 1 if $hw =~/x86_64|ia32e/; } use constant CRACKLIB => ($word64 ? "/usr/lib64/cracklib_dict" : "/usr +/lib/cracklib_dict");
        perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'
Re: Unable to assign value to constants using ternary operator
by marto (Cardinal) on May 11, 2012 at 10:04 UTC