Perl does have a return statement. You can return the variables.
use strict; use warnings; my $test = foo(); print $test."\n"; sub foo { return "Hello World!"; }


Your question regarding my and local deals with variable scoping. I could explain here, but here is a link that does it quite well. http://perl.plover.com/FAQs/Namespaces.html

For the record, my isn't the answer here. My creates a variable that exists only within the scope it was created in. If you create it in a sub, it lasts only inside that sub. If you create it in the main part of the script, it'll last throughout the file including the subs.

local is a tricky subject. There are monks with better knowledge of it than me, but the basics are that it creates a localized version of a global sub it takes a global variable, stores the value somewhere safe, gives it a new value. That value is then used until the end of the control block where the original value is give back to the variable. It was created before my and most perl programmers do not use it anymore.

In reply to Re: Several stupid questions about subs by fidesachates
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.