Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl shift operator simple question

Tags:

perl

shift

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

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

That should return localhost and port 10. What is the shift keyword??

like image 786
Marco A. Avatar asked May 21 '11 09:05

Marco A.


1 Answers

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.

like image 182
DavidO Avatar answered Dec 04 '22 09:12

DavidO