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

Hi all , I am new to perl . I was trying to do the following : my Unix .profile contain the following variable
$one = 2233 $two = 3434
in my perl script I am trying to set a value equal to $one/$two which in this case should be 2233/3434 I am doing the following :
my $value = system('$one/$two'); print "my value is $value\n";
it is not working for me , I get the following :
2233/3434 my value is
so I am not getting any thing sat to value but I could see the output. What is wrong ?

Replies are listed 'Best First'.
Re: unix command with system
by neuroball (Pilgrim) on Jan 17, 2004 at 00:58 UTC

    What is wrong?

    Not much, I almost saw a stroke of genius in what you tried to do. The only problem for you is, that unix shells don't work like calculators.

    What you want to archive can be done by using the following code:

    my $value =$ENV{"one"} / $ENV{"two"}; print "my value is $value\n";

    $ENV{x} allows you access to the value that is stored in the environment variable x.

    /oliver/

      thanks all
Re: unix command with system
by b10m (Vicar) on Jan 17, 2004 at 00:42 UTC

    If you're talking about simple variables, try this in your ~/.profile:

    ONE=2233 TWO=3434 export ONE TWO

    And than use the following in your script:

    my $value = "$ENV{ONE}/$ENV{TWO}"; print "my value is $value\n";

    Update: I figured, you wanted to get "2233/3434" as a result (as in a directory tree), but if you want what neuroball suggests below, please ignore my suggestion, as far as the quotes go ;)

    --
    b10m
Re: unix command with system
by dominix (Deacon) on Jan 17, 2004 at 07:59 UTC
    Some Monks have given you a better way to use your environmental values, but if you still want to use system command you have to output something and get it back using backtick if you want it to be stored in a variable, because (perl 's)system return an exit status, not the output of the command eg
    my $value = `echo $one/$two`;
    --
    dominix
Re: unix command with system
by jweed (Chaplain) on Jan 17, 2004 at 00:47 UTC