Personally I never use local and as far as I am aware you shouldn't either! Perl does have a return statement!
my $var = foo(); sub foo { return 'bar'; } print $var;
what you get printed out is the word 'bar'. if you want to pass variables to a sub there are various ways;
my $var = foo('some_text_for_instance'); sub foo { my $text = $_[0]; return 'bar'; }
As far as I understand it $_[0], represents the first element of an array sent to the sub... so if you can do stuff like this;
my $var = foo($somevar,"some text",$somehashref); sub foo { my $variable = $_[0]; my $text = $_[1]; my $hashref = $_[2]; return $hashref->{'some_key'}; }
You can also capture the whole passed array;
sub foo { my @private_local_array = @_; #then lets return element 5 for some reason return $private_local_array[4]; }
There is also my $var = shift; but I'm not sure what that is or does or why one would want to use it.

In reply to Re: Several stupid questions about subs by simonodell
in thread Several stupid questions about subs by bryan172

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.