On 3 Jul 2006 at 3:04, Umar Draz wrote:

> hi dear members!
> 
>   i am new in Perl community i want to declare a function and try to pass 
> some parameters same as i do in php. First i declare a function (umar).
> 
> 
> sub umar ($width, $height) {
>     $area = $width * $height / 2;
>     return $area;
> }

Generally when you create a function, you do not declare the variables in this 
way. The usual 
practise is like this:  

sub umar {
 my $width = shift;             # First arg will be the width.
 my $height = shift;            # Second arg will be the height.
 my $area = ($width * $height) / 2;
 return $area;
}

> after that is I call function through a variable
> $result = umar(10,40);
> print "$result\n";
> 
> But it did't work and i got a error
> 
> Illegal character in prototype for main::umar : $width,$height at ./test.pl 
> line 7.
> Malformed prototype for main::umar: $width,$height at ./test.pl line 12.

HTH 
Dp.


Dermot Paikkos

[EMAIL PROTECTED]
Network Administrator @ Science Photo Library
Phone: 0207 432 1100 
Fax: 0207 286 8668

Reply via email to