You are passing in a reference to an array in the function. References are scalars. The line
my @xpid = shift;
is very misleading. All it does is create a one element array @xpid, whose only element is a reference to the original array. It's better to write the first line as:
my $xpid_ref = shift;

Then, to deference a reference (to get to its juicy content), you place the appropriate sigil in front of the reference (or the block that results in the reference). So, your loop would start with:

foreach my $item (@$xpid_ref) {
Furthermore, if you are looping over an array with
foreach my $element (@array)
don't use an index to get to the element! You already have it in your variant: $element. So, you'd write your loop as:
foreach my $item (@$xpid_ref) { $return .= $item; }
Of course, the entire function body can be reduced to a one-liner:
return join "" => @{+shift}
and then you can take the 'return' off as well.

Abigail


In reply to Re: Help w passing array by ref by Abigail-II
in thread Help w passing array by ref by alienhuman

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.