place and plays @_ in perl?
sub Addition{ $a=\@_; ($a,$b,$c)=@$a; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
sub Addition{ ($a,$b,$c)=grep $_ ,@_; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
Method 3:
sub Addition{ ($a,$b,$c)=map $_ ,@_; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
Method 4:
sub Addition{ ($a,$b,$c)=@_[0..$#_]; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
Method 5:
sub Addition{ @a=@_; $sum=$a[0]+$a[1]+$a[2]; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
sub Addition{ ($a,$b,$c)=@_; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
Method 7:
sub Addition{ $a=shift @_; $b=shift @_; $c=shift @_; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
Method 8:
sub Addition{ $a=$_[0]; $b=$_[1]; $c=$_[2]; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
Method 9:
sub Addition{ $a=@_[0]; $b=@_[1]; $c=@_[2]; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
Method 10:
sub Addition{ $a=shift; $b=shift; $c=shift; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
sub Addition{ foreach $item (@_){ $sum += $item; } } Addtion(10, 20, 30); print $sum; #60
Method 12:
sub Addition{ $a=pop @_; $b=pop @_; $c=pop @_; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
Method 13:
sub Addition{ $a=pop; $b=pop; $c=pop; $sum=$a+$b+$c; } Addtion(10, 20, 30); print $sum; #60
NOTE: Change the variable assignation reverse if u want for methods 12,13
Labels: place and plays @_ in perl?
0 Comments:
Post a Comment
Note: only a member of this blog may post a comment.
<< Home