Perl Tutorials -Part 89- Arguments

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


#perl example of subroute arguments
sub makeCuppa
{  if($_[1])
   {
     $colour = 'white';
   }
   else
   {
     $colour = 'black';
   }
     print "Here is a cup of $colour $_[0] with $_[2] sugar.\n";
}

makeCuppa('tea', 0, 1);
makeCuppa('coffee', 1, 5);

Here is a cup of black tea with 1 sugar.
Here is a cup of white coffee with 5 sugar.
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: