perlのメソッド

perlでは、ファンクションのことをサブルーチン(ユーザ関数)と呼ぶらしい。

#サブルーチン
$x = 123;
$y = 234;
$t = 99;

&total;
$to = &func_sum($x,$y,$t);
print $to."\n";

#引数、戻り値なし
sub total{
  $z = $x + $y;
  print "total="."$z\n";
}

#引数、戻り値あり
sub func_sum{
  ($x0, $y0, $t0) = @_;
  $z = $x0 + $y0 + $t0;
  return $z;
}