<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.scott5.org/index.php?action=history&amp;feed=atom&amp;title=Perl_Subroutines</id>
	<title>Perl Subroutines - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.scott5.org/index.php?action=history&amp;feed=atom&amp;title=Perl_Subroutines"/>
	<link rel="alternate" type="text/html" href="https://wiki.scott5.org/index.php?title=Perl_Subroutines&amp;action=history"/>
	<updated>2026-05-27T20:45:03Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://wiki.scott5.org/index.php?title=Perl_Subroutines&amp;diff=202&amp;oldid=prev</id>
		<title>Scott: Created page with &#039;== Define == &lt;source lang=&quot;perl&quot;&gt; sub hypotenuse {     return sqrt( ($_[0] ** 2) + ($_[1] ** 2) ); # &quot;return&quot; is optional } sub print_name_and_age {     my ($name, $age) = @_;   …&#039;</title>
		<link rel="alternate" type="text/html" href="https://wiki.scott5.org/index.php?title=Perl_Subroutines&amp;diff=202&amp;oldid=prev"/>
		<updated>2011-02-01T18:21:01Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;== Define == &amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt; sub hypotenuse {     return sqrt( ($_[0] ** 2) + ($_[1] ** 2) ); # &amp;quot;return&amp;quot; is optional } sub print_name_and_age {     my ($name, $age) = @_;   …&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== Define ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
sub hypotenuse {&lt;br /&gt;
    return sqrt( ($_[0] ** 2) + ($_[1] ** 2) ); # &amp;quot;return&amp;quot; is optional&lt;br /&gt;
}&lt;br /&gt;
sub print_name_and_age {&lt;br /&gt;
    my ($name, $age) = @_;   # @_ is the calling context array&lt;br /&gt;
    print &amp;quot;$name is $age years old.\n&amp;quot;;&lt;br /&gt;
    my $same_name = $_[0];   # first arg of @_ array&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Call ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
$diag = hypotenuse(3,4);  # $diag is 5&lt;br /&gt;
$diag = &amp;amp;hypotenuse(3,4);  # the &amp;amp; is optional&lt;br /&gt;
print_name_and_age(&amp;quot;Lassie&amp;quot;, 3); # @_ defined to be (&amp;quot;Lassie&amp;quot;, 3)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Required arguments ==&lt;br /&gt;
Change the first line above to &lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
sub print_name_and_age($$) {&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
to require two scalar arguments. &lt;br /&gt;
&lt;br /&gt;
== Passing arrays and hashes ==&lt;br /&gt;
Use references to operate on the passed data &lt;br /&gt;
&amp;lt;source lang=&amp;quot;perl&amp;quot;&amp;gt;&lt;br /&gt;
sub my_function($$){&lt;br /&gt;
    my %hash = %{$_[0]};&lt;br /&gt;
    my @array = @{$_[1]};&lt;br /&gt;
    ...&lt;br /&gt;
}&lt;br /&gt;
my_function(\%the_hash, \@the_array);&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
A subroutine may return an array or hash, too.&lt;/div&gt;</summary>
		<author><name>Scott</name></author>
	</entry>
</feed>