Saturday, October 18, 2008

Write methods in perl

Find the maximum value of the array

#!/usr/bin/perl -w

# find the maximum value of the array

$maxVal=maximum(2,10,1,9,3,12);
print("\n\nThe Maximum is : $maxVal \n");

sub maximum
{

$val=$_[0];

foreach $my(@_)
{
if($my > $val)
{
$val=$my;
print("\n Max value change to $val");
}
}
return $val;
}

No comments: