Perl Tutorials -Part 91 – Explicit returns

Posted on June 7, 2010. Filed under: Perl Tutorials |


#perl example of subroute that returns a value
#'$$' means expect two scale variables as parameters
sub compareNumbers ($$)
{
   $first = $_[0];
   $second = $_[1];
   if ($first > $second)
   {
     return "$first is bigger than $second";
   }
   elsif ($first < $second)
   {
     return "$first is smaller than $second";
   }
   else
   {
     return "they are probably equal";
   }
}

print compareNumbers 3, 1;
3 is bigger than 1
Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: