how do I access ksh environment array variables in perl?

Discussion in 'Perl Misc' started by Andy Haupt, Mar 24, 2005.

  1. Andy Haupt

    Andy Haupt Guest

    hello,

    in ksh you can set array variables like
    a[1]=x
    a[4]=y
    and access them like
    echo ${a[1]}

    how do I access this array in Perl?

    $ENV{"a"} retrieves 'x' (the value of a[1])
    keys %ENV lists 'a' amongst its vars

    but how do I
    find out that a is an array, the length of a and its
    subscripts and values?


    rgds
    andy
    Andy Haupt, Mar 24, 2005
    #1
    1. Advertising

  2. Andy Haupt wrote:

    > hello,
    >
    > in ksh you can set array variables like
    > a[1]=x
    > a[4]=y
    > and access them like
    > echo ${a[1]}
    >
    > how do I access this array in Perl?


    You don't. Array variables are Korn Shell specific;
    they can only be set and accessed from the Korn shell.
    If you leave ksh, the only thing accessible is the
    first element of the array under the name of the array.
    >
    > $ENV{"a"} retrieves 'x' (the value of a[1])
    > keys %ENV lists 'a' amongst its vars


    Correct. You have access to the first element of the
    array, which gets listed under the name of the array.
    >
    > but how do I
    > find out that a is an array, the length of a and its
    > subscripts and values?


    You don't, because you can't. Once you leave the
    Korn Shell, you lose all your arrays. Perl doesn't
    inherit them.
    >
    >
    > rgds
    > andy


    --
    Christopher Mattern

    "Which one you figure tracked us?"
    "The ugly one, sir."
    "...Could you be more specific?"
    Chris Mattern, Mar 24, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. kaeli
    Replies:
    8
    Views:
    1,377
    Harald Kirsch
    Feb 13, 2004
  2. Replies:
    12
    Views:
    2,423
    Magnus Lycka
    Jun 8, 2005
  3. E Arredondo

    ksh after perl script

    E Arredondo, Oct 4, 2005, in forum: Perl Misc
    Replies:
    7
    Views:
    251
    Tintin
    Oct 5, 2005
  4. Replies:
    4
    Views:
    109
    Ben Morrow
    Apr 4, 2008
  5. Jose Luis
    Replies:
    3
    Views:
    159
    Jose Luis
    Aug 13, 2009
Loading...

Share This Page