Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Unable to assign value to constants using ternary operator

by sathya_myl (Acolyte)
on May 11, 2012 at 10:01 UTC ( #969961=perlquestion: print w/ replies, xml ) Need Help??
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

Comment on Unable to assign value to constants using ternary operator
Download Code
Re: Unable to assign value to constants using ternary operator
by marto (Chancellor) on May 11, 2012 at 10:04 UTC
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'

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://969961]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2013-05-19 19:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (397 votes), past polls