Like Anon says above, shell arrays are a concept internal to the shell, they can't be exported.

Here are some things you could do if you still want to pass an array of string. The easiest way might be to pass the values of the array as command-line arguments and access them as @ARGV.

perl -we 'print "<<<$_>>>\n" for @ARGV;' -- "${NUMS[@]}"
You could also write the values to a file (either a regular file or pipe) separated by nuls, and read that file from perl, eg.
printf "%s\0" "${NUMS[@]}" | perl -we 'my @NUMS; { local $/ = "\0"; ch +omp(@NUMS = <STDIN>); }; warn "<<<$_>>>\n" for @NUMS; '

You needn't use the standard input, you can pass the name or filedescriptor of the file to the script in the command line or environment.

You could also avoid files and stuff the values in separate environment variables, but that gets ugly, so I recommend files instead.

for k in "${!NUMS[@]}"; do export NUMS_$k=${NUMS[k]}; done; perl -we 'my @NUMS; while (my($k, $v) = each %ENV) { $k =~ /\ANUMS_(.+ +)\z/ and $NUMS[$1] = $v; } print "<<<$_>>>\n" for @NUMS;'

In reply to Re: Environment variable is an array by ambrus
in thread Environment variable is an array by stevenswj

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.