Hello Monks,

I was in the middle of writing a sub/function in my script and I was curious about the following circumstance, and was
wondering if one of the methods below is preferred or recommended over the other. The situation is when you pass ONLY
a single argument to a sub-routine. So there will only ever be one argument passed to my sub/function...

Is one of these methods preferred/recommended over the other:

METHOD #1
sub myFunction { my $arg = shift; #blah blah blah, do some stuff..... } myFunction($myArg);

METHOD #2
sub myFunction { my $arg = @_; #blah blah blah, do some stuff..... } myFunction($myArg);

METHOD #3
sub myFunction { my $arg = $_[0]; #blah blah blah, do some stuff..... } myFunction($myArg);

I'm not sure if there are other ways to grab the argument besides those, but are any of those the preferred/recommended
method over the other?


Thanks in Advance,
Matt


In reply to User-Defined Sub, Passing a Single Argument? by mmartin

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.