As detailed in DESCRIPTION in perlsub, variables passed into a subroutine are stored in the special @_ array. The shift at the start of your subroutine implicitly accesses this array. Since $nic is presumably a hash reference and thus a scalar, you could access it with:

sub getPlatformFiles { my $plat_in = shift; my $nic = shift; my @list;

A style I prefer when not using OO-style programming is to use an list assignment rather than a shift, but this is wholly subjective:

sub getPlatformFiles { my ($plat_in, $nic) = @_; my @list;

There are some potential complexities involved in scoping here, which may bite you if you are incautious and use the same variable names in a script and a subroutine. Note the following is for demonstration purposes and using this approach without good reason can result in some painful bug hunting. If you declare a variable with my in scoping using that contains a subroutine, that subroutine can see all variables in that scope, and hence the following works:

#!/usr/bin/perl use strict; use warnings; my $variable = "Hello\n"; outputter(); sub outputter { print $variable; }

This is because the scope of $variable is at the script level and contains the subroutine definition. On the other hand, the following will output an error message:

#!/usr/bin/perl use strict; use warnings; sub outputter { print $variable; } my $variable = "Hello\n"; outputter();
because the variable is not declared prior to its use in the subroutine. These behaviors allow for some very powerful structures called closures.

In reply to Re: Another scoping issue: How do I send 2 variables to my sub and use both. by kennethk
in thread Another scoping issue: How do I send 2 variables to my sub and use both. by MikeDexter

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.