Perl shift operator simple question

后端 未结 5 1949
离开以前
离开以前 2021-01-19 03:33

What\'s the purpose of the following two lines of perl??

my $host = shift || \'localhost\';
my $port = shift || 200;

That should return loc

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-19 04:16

    The first line shifts from either @_ or @ARGV (depending on where you are in the code), or in the absence of any contents in @_/@ARGV, assigns localhost to $host.

    The second one should be self-explanatory now.

    Have a look at the shift documentation for details.

提交回复
热议问题