Hi ,

The arrays when input to a function will be obtained as a list and hence your first array alone gets assigned from the @_ , the array have to be passed as REFERENCE and then the return exits from the function and hence you can use only one of the returns and get the value from the calling part of it
use Data::Dumper; my @seg1 = ("fkgskfgskfgksf","kshflkshfkls"); my @seg2 = ("kgskfgskf","sjfgsjfgjsgfksf"); #create references my $seg1 = \@seg1; my $seg2 = \@seg2; my $seg3 = \@seg3; my $seg4 = \@seg4; my $seg5 = \@seg5; my @pairs = get_pairs($seg1,$seg2,$seg3,$seg4,$seg5); print Dumper \@pairs; sub get_pairs { my @seg_pairs = @_; map {for my $i (1..scalar(@$_)){ push (@pairs , "$_->[$i-1] $_->[$i]\n");} }@seg_pairs; return @pairs; }


The usages of references are many and this is one of the ways to do it

the reference is pushed to an array and the array is passed to the function

the arrays are gotten by doing a dereference and then an array is pushed for that you should have

the array is obtained and the using Data::Dumper is printed and then you could do that you rerquire with it


In reply to Re: subroutines + returning more than 1 value by OM_Zen
in thread subroutines + returning more than 1 value by Anonymous Monk

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.