What does the value of $ mean? $ in the Perl function definition?

I got the following code:

sub deg2rad ($;$) { my $d = _DR * $_[0]; $_[1] ? $d : rad2rad($d) }

Can someone tell me what it means $;$?

+4
source share
1 answer

The material in parentheses behind the subtask is called the prototype. They are explained in perlsub . In general, you can use them to check compilation time limits.

Concrete is ($;$)used for required arguments.

A semicolon (;) separates required arguments from optional arguments. It is redundant to @ or%, which will gobble up everything else

So, sub must be called with at least one argument , but may have a second .

, .

use constant _DR => 1;
sub rad2rad       {@_}
sub deg2rad ($;$) { my $d = _DR * $_[0]; $_[1] ? $d : rad2rad($d) }

print deg2rad(2, 3, 4);

__END__

Too many arguments for main::deg2rad at scratch.pl line 409, near "4)"
Execution of scratch.pl aborted due to compilation errors.

, , $foo->frobnicate().

, ​​ Perl , , .

, :

, , , , , , -, .

. .

+10

Source: https://habr.com/ru/post/1611605/


All Articles