As mentioned in perlsub, parameters passed into a subroutine are passed as a flat list. From the subroutine's perspective, it's impossible to determine where @VRF_names ends, and @spines_ip begins. It's all just a flat list of values.

You want to pass in a reference to an array:

sub BuildLeaf { my ( $hostname, $lo_add, $ospf_process, $ospf_area, $bgp_as, $bgp_pass, $VRF_names_aref, $spines_ip_aref ) = @_; # Do your stuff here. }

And then in the sub call, change @{$vrf_info[0]} and @{$spine_info[1]} to $vrf_info[0] and $spine_info[1]. Within the subroutine, you will need to dereference the array-refs appropriately. See perlref and perlreftut for details. We can't really guess how you might be using the passed-in arrays without seeing the code, so it would be impractical for us to demonstrate the appropriate array-ref dereferencing for your particular use case. But the documentation is good, although possibly a bit opaque on first read. The online book Modern Perl would probably offer a gentler introduction to wielding references.


Dave


In reply to Re: Pass Arrays to a subroutine by davido
in thread Pass Arrays to a subroutine by sankoshy

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.