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

Im trying to modify a ksh variable in a perl code

result="" string="col1;col2;col3" perl -e ' $str="'$string'"; @list = split(/;/,$str); ***Here i want that result = @list **** ' echo result

Replies are listed 'Best First'.
Re: modify ksh variable in perl
by pc88mxer (Vicar) on Apr 17, 2008 at 16:38 UTC
    You can't modify a ksh variable from perl, but you can set a ksh variable to the output of a perl program:
    result=$(perl -e ...)
    To set an array variable, you can use:
    set -A arrayvar $(perl -e ...)
    Update: For your specific case, this might work well enough:
    set -A result $(echo $string | sed -e 's/;/ /g')
      Revised: Exit returns a number only; of limited use when setting environmental variables. Plesae reap.

      Or, if it's more than a one-liner, the Perl script should end with

      exit( $returned_value );

Re: modify ksh variable in perl
by moritz (Cardinal) on Apr 17, 2008 at 16:43 UTC
    If you want to access the environment variables from perl you need to use $ENV{string}.

    That only works for real environment variables, I don't know if ksh exports its internal variables by default.

    Modifying an environment variable will not modify it in the calling shell, though.